Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(service-worker): fix LruList 'remove' bug #22769

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 6 additions & 19 deletions packages/service-worker/worker/src/data.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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--;

Expand Down