Skip to content

Commit 65f8943

Browse files
adasilvaIgorMinar
adasilva
authored andcommitted
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
1 parent 5391f96 commit 65f8943

File tree

1 file changed

+6
-19
lines changed
  • packages/service-worker/worker/src

1 file changed

+6
-19
lines changed

packages/service-worker/worker/src/data.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,7 @@ class LruList {
9999
}
100100

101101
const url = this.state.tail;
102-
103-
// Special case if this is the last node.
104-
if (this.state.head === this.state.tail) {
105-
// When removing the last node, both head and tail pointers become null.
106-
this.state.head = null;
107-
this.state.tail = null;
108-
} else {
109-
// Normal node removal. All that needs to be done is to clear the next pointer
110-
// of the previous node and make it the new tail.
111-
const block = this.state.map[url] !;
112-
const previous = this.state.map[block.previous !] !;
113-
this.state.tail = previous.url;
114-
previous.next = block.next;
115-
}
116-
117-
// In any case, this URL is no longer tracked, so remove it from the count and the
118-
// map of tracked URLs.
119-
delete this.state.map[url];
120-
this.state.count--;
102+
this.remove(url);
121103

122104
// This URL has been successfully evicted.
123105
return url;
@@ -145,6 +127,8 @@ class LruList {
145127
const next = this.state.map[node.next !] !;
146128
next.previous = null;
147129
this.state.head = next.url;
130+
node.next = null;
131+
delete this.state.map[url];
148132
this.state.count--;
149133
return true;
150134
}
@@ -167,6 +151,9 @@ class LruList {
167151
this.state.tail = node.previous !;
168152
}
169153

154+
node.next = null;
155+
node.previous = null;
156+
delete this.state.map[url];
170157
// Count the removal.
171158
this.state.count--;
172159

0 commit comments

Comments
 (0)