Skip to content

Commit

Permalink
Fix stray lists in redesigned cache storage
Browse files Browse the repository at this point in the history
Related issue:
https://old.reddit.com/r/uBlockOrigin/comments/1bxzwf9/

These stray filter lists prevents uBO from properly updating
those filter lists.
  • Loading branch information
gorhill committed Apr 7, 2024
1 parent 98a6006 commit defd68e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/js/cachestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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);
},

Expand Down

0 comments on commit defd68e

Please sign in to comment.