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.
This commit is contained in:
Raymond Hill 2024-04-07 18:21:37 -04:00
parent 98a600698e
commit defd68ef7d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 16 additions and 12 deletions

View File

@ -486,16 +486,9 @@ const idbStorage = (( ) => {
// Cache API is subject to quota so we will use it only for what is key // Cache API is subject to quota so we will use it only for what is key
// performance-wise // performance-wise
const shouldCache = bin => { const shouldCache = key => {
const out = {}; if ( key.startsWith('cache/') === false ) { return true; }
for ( const key of Object.keys(bin) ) { return /^cache\/(compiled|selfie)\//.test(key);
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 fromBlob = data => { const fromBlob = data => {
@ -669,7 +662,12 @@ const idbStorage = (( ) => {
if ( keys.length === 0 ) { return getAll(); } if ( keys.length === 0 ) { return getAll(); }
const entries = await getEntries(keys); const entries = await getEntries(keys);
const outbin = {}; const outbin = {};
const toRemove = [];
for ( const { key, value } of entries ) { for ( const { key, value } of entries ) {
if ( shouldCache(key) === false ) {
toRemove.push(key);
continue;
}
outbin[key] = value; outbin[key] = value;
} }
if ( argbin instanceof Object && Array.isArray(argbin) === false ) { if ( argbin instanceof Object && Array.isArray(argbin) === false ) {
@ -678,12 +676,18 @@ const idbStorage = (( ) => {
outbin[key] = argbin[key]; outbin[key] = argbin[key];
} }
} }
if ( toRemove.length !== 0 ) {
deleteEntries(toRemove);
}
return outbin; return outbin;
}, },
async set(rawbin) { async set(rawbin) {
const bin = shouldCache(rawbin); const bin = {};
if ( bin === undefined ) { return; } for ( const key of Object.keys(rawbin) ) {
if ( shouldCache(key) === false ) { continue; }
bin[key] = rawbin[key];
}
return setEntries(bin); return setEntries(bin);
}, },