From 8c2a57878b04d0bda67096b2cbc0f2736b8db27d Mon Sep 17 00:00:00 2001 From: adasilva Date: Wed, 14 Mar 2018 14:30:38 -0400 Subject: [PATCH] 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 --- packages/service-worker/worker/src/data.ts | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/service-worker/worker/src/data.ts b/packages/service-worker/worker/src/data.ts index 5608611888..e1d98f2951 100644 --- a/packages/service-worker/worker/src/data.ts +++ b/packages/service-worker/worker/src/data.ts @@ -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--;