fix(service-worker): fix LruList bugs (#22769)

'remove' method not removing url from state.map
'accessed' method not removing 'previous' reference from existing  node when it becomes the head

Fixes #22218
Fixes #22768

PR Close #22769
This commit is contained in:
adasilva 2018-03-14 14:30:38 -04:00 committed by Igor Minar
parent 4f2c51fe56
commit 8c2a57878b
1 changed files with 6 additions and 19 deletions

View File

@ -99,25 +99,7 @@ class LruList {
} }
const url = this.state.tail; const url = this.state.tail;
this.remove(url);
// Special case if this is the last node.
if (this.state.head === this.state.tail) {
// When removing the last node, both head and tail pointers become null.
this.state.head = null;
this.state.tail = null;
} else {
// Normal node removal. All that needs to be done is to clear the next pointer
// of the previous node and make it the new tail.
const block = this.state.map[url] !;
const previous = this.state.map[block.previous !] !;
this.state.tail = previous.url;
previous.next = block.next;
}
// In any case, this URL is no longer tracked, so remove it from the count and the
// map of tracked URLs.
delete this.state.map[url];
this.state.count--;
// This URL has been successfully evicted. // This URL has been successfully evicted.
return url; return url;
@ -145,6 +127,8 @@ class LruList {
const next = this.state.map[node.next !] !; const next = this.state.map[node.next !] !;
next.previous = null; next.previous = null;
this.state.head = next.url; this.state.head = next.url;
node.next = null;
delete this.state.map[url];
this.state.count--; this.state.count--;
return true; return true;
} }
@ -167,6 +151,9 @@ class LruList {
this.state.tail = node.previous !; this.state.tail = node.previous !;
} }
node.next = null;
node.previous = null;
delete this.state.map[url];
// Count the removal. // Count the removal.
this.state.count--; this.state.count--;