diff --git a/src/js/assets.js b/src/js/assets.js index 6484d289d..77e9b8167 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -696,15 +696,14 @@ function getAssetCacheRegistry() { const saveAssetCacheRegistry = (( ) => { const save = ( ) => { timer.off(); - cacheStorage.set({ assetCacheRegistry }); + return cacheStorage.set({ assetCacheRegistry }); }; const timer = vAPI.defer.create(save); - return function(lazily) { - if ( lazily ) { - timer.offon({ sec: 30 }); - } else { - save(); + return (throttle = 0) => { + if ( throttle === 0 ) { + return save(); } + timer.offon({ sec: throttle }); }; })(); @@ -741,7 +740,7 @@ async function assetCacheRead(assetKey, updateReadTime = false) { entry.readTime = Date.now(); if ( updateReadTime ) { - saveAssetCacheRegistry(true); + saveAssetCacheRegistry(23); } return reportBack(bin[internalKey]); @@ -752,18 +751,20 @@ async function assetCacheWrite(assetKey, content, options = {}) { return assetCacheRemove(assetKey); } - const { resourceTime, url } = options; + const cacheDict = await getAssetCacheRegistry(); - getAssetCacheRegistry().then(cacheDict => { - const entry = cacheDict[assetKey] || {}; - cacheDict[assetKey] = entry; - entry.writeTime = entry.readTime = Date.now(); - entry.resourceTime = resourceTime || 0; - if ( typeof url === 'string' ) { - entry.remoteURL = url; - } - cacheStorage.set({ assetCacheRegistry, [`cache/${assetKey}`]: content }); - }); + const { resourceTime, url } = options; + const entry = cacheDict[assetKey] || {}; + entry.writeTime = entry.readTime = Date.now(); + entry.resourceTime = resourceTime || 0; + if ( typeof url === 'string' ) { + entry.remoteURL = url; + } + cacheDict[assetKey] = entry; + + await cacheStorage.set({ [`cache/${assetKey}`]: content }); + + saveAssetCacheRegistry(3); const result = { assetKey, content }; // https://github.com/uBlockOrigin/uBlock-issues/issues/248 diff --git a/src/js/cachestorage.js b/src/js/cachestorage.js index 774ab016b..e0fe98705 100644 --- a/src/js/cachestorage.js +++ b/src/js/cachestorage.js @@ -87,7 +87,7 @@ const cacheStorage = (( ) => { data.length >= µbhs.cacheStorageCompressionThreshold; const after = await scuo.serializeAsync(data, { compress: isLarge && µbhs.cacheStorageCompression, - multithreaded: isLarge && µbhs.cacheStorageMultithread || 0, + multithreaded: isLarge && µbhs.cacheStorageMultithread || 2, }); return { key, data: after }; }; @@ -98,7 +98,7 @@ const cacheStorage = (( ) => { const µbhs = µb.hiddenSettings; const isLarge = data.length >= µbhs.cacheStorageCompressionThreshold; bin[key] = await scuo.deserializeAsync(data, { - multithreaded: isLarge && µbhs.cacheStorageMultithread || 0, + multithreaded: isLarge && µbhs.cacheStorageMultithread || 2, }); }; diff --git a/src/js/storage.js b/src/js/storage.js index 68b52209d..99116547e 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -1300,6 +1300,7 @@ onBroadcast(msg => { catch (reason) { ubolog(reason); } + ubolog('Selfie not available'); destroy(); return false; }; @@ -1308,7 +1309,7 @@ onBroadcast(msg => { if ( µb.selfieIsInvalid === false ) { io.remove(/^selfie\//, options); µb.selfieIsInvalid = true; - ubolog(`Selfie was removed`); + ubolog('Selfie marked for invalidation'); } if ( µb.wakeupReason === 'createSelfie' ) { µb.wakeupReason = '';