From defd68ef7d7d3c07449b5c965840b88ca878837b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 7 Apr 2024 18:21:37 -0400 Subject: [PATCH] Fix stray lists in redesigned cache storage Related issue: https://old.reddit.com/r/uBlockOrigin/comments/1bxzwf9/ These stray filter lists prevents uBO from properly updating those filter lists. --- src/js/cachestorage.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/js/cachestorage.js b/src/js/cachestorage.js index 78049a9b9..38a6533be 100644 --- a/src/js/cachestorage.js +++ b/src/js/cachestorage.js @@ -486,16 +486,9 @@ const idbStorage = (( ) => { // Cache API is subject to quota so we will use it only for what is key // performance-wise - const shouldCache = bin => { - const out = {}; - for ( const key of Object.keys(bin) ) { - if ( key.startsWith('cache/' ) ) { - if ( /^cache\/(compiled|selfie)\//.test(key) === false ) { continue; } - } - out[key] = bin[key]; - } - if ( Object.keys(out).length === 0 ) { return; } - return out; + const shouldCache = key => { + if ( key.startsWith('cache/') === false ) { return true; } + return /^cache\/(compiled|selfie)\//.test(key); }; const fromBlob = data => { @@ -669,7 +662,12 @@ const idbStorage = (( ) => { if ( keys.length === 0 ) { return getAll(); } const entries = await getEntries(keys); const outbin = {}; + const toRemove = []; for ( const { key, value } of entries ) { + if ( shouldCache(key) === false ) { + toRemove.push(key); + continue; + } outbin[key] = value; } if ( argbin instanceof Object && Array.isArray(argbin) === false ) { @@ -678,12 +676,18 @@ const idbStorage = (( ) => { outbin[key] = argbin[key]; } } + if ( toRemove.length !== 0 ) { + deleteEntries(toRemove); + } return outbin; }, async set(rawbin) { - const bin = shouldCache(rawbin); - if ( bin === undefined ) { return; } + const bin = {}; + for ( const key of Object.keys(rawbin) ) { + if ( shouldCache(key) === false ) { continue; } + bin[key] = rawbin[key]; + } return setEntries(bin); },