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:
parent
4f2c51fe56
commit
8c2a57878b
|
@ -99,25 +99,7 @@ class LruList {
|
|||
}
|
||||
|
||||
const url = this.state.tail;
|
||||
|
||||
// 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.remove(url);
|
||||
|
||||
// This URL has been successfully evicted.
|
||||
return url;
|
||||
|
@ -145,6 +127,8 @@ class LruList {
|
|||
const next = this.state.map[node.next !] !;
|
||||
next.previous = null;
|
||||
this.state.head = next.url;
|
||||
node.next = null;
|
||||
delete this.state.map[url];
|
||||
this.state.count--;
|
||||
return true;
|
||||
}
|
||||
|
@ -167,6 +151,9 @@ class LruList {
|
|||
this.state.tail = node.previous !;
|
||||
}
|
||||
|
||||
node.next = null;
|
||||
node.previous = null;
|
||||
delete this.state.map[url];
|
||||
// Count the removal.
|
||||
this.state.count--;
|
||||
|
||||
|
|
Loading…
Reference in New Issue