mirror of
https://github.com/gorhill/uBlock.git
synced 2025-01-31 20:21:35 +01:00
Fix race condition when saving cache registry
Related to new cache storage code.
This commit is contained in:
parent
e8b7037ba8
commit
b0fc5d3d21
@ -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
|
||||
|
@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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 = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user