mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 11:22:38 +01:00
Wait for removal of storage entries to be completed
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1365 When compiled data format changes, do not rely on order of operations at launch to assume deletion of storage occurs before attempts to access it. It's unclear this commit will fix the reported issue, as I could not reproduce it except when outright commenting out the code to prevent the storage deletion from occurring.
This commit is contained in:
parent
da9d068243
commit
e8e4a1ac74
@ -603,14 +603,15 @@ const assetCacheRemove = async function(pattern) {
|
|||||||
delete cacheDict[assetKey];
|
delete cacheDict[assetKey];
|
||||||
}
|
}
|
||||||
if ( removedContent.length !== 0 ) {
|
if ( removedContent.length !== 0 ) {
|
||||||
µBlock.cacheStorage.remove(removedContent);
|
await Promise.all([
|
||||||
µBlock.cacheStorage.set({ assetCacheRegistry });
|
µBlock.cacheStorage.remove(removedContent),
|
||||||
|
µBlock.cacheStorage.set({ assetCacheRegistry }),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
for ( let i = 0; i < removedEntries.length; i++ ) {
|
for ( let i = 0; i < removedEntries.length; i++ ) {
|
||||||
fireNotification(
|
fireNotification('after-asset-updated', {
|
||||||
'after-asset-updated',
|
assetKey: removedEntries[i]
|
||||||
{ assetKey: removedEntries[i] }
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -185,10 +185,12 @@ const onUserSettingsReady = function(fetched) {
|
|||||||
|
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1588916
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1588916
|
||||||
// Save magic format numbers into the cache storage itself.
|
// Save magic format numbers into the cache storage itself.
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
|
||||||
|
// Wait for removal of invalid cached data to be completed.
|
||||||
|
|
||||||
const onCacheSettingsReady = function(fetched) {
|
const onCacheSettingsReady = async function(fetched) {
|
||||||
if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) {
|
if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) {
|
||||||
µb.assets.remove(/^compiled\//);
|
await µb.assets.remove(/^compiled\//);
|
||||||
µb.compiledFormatChanged = true;
|
µb.compiledFormatChanged = true;
|
||||||
µb.selfieIsInvalid = true;
|
µb.selfieIsInvalid = true;
|
||||||
}
|
}
|
||||||
@ -292,15 +294,18 @@ try {
|
|||||||
);
|
);
|
||||||
log.info(`Backend storage for cache will be ${cacheBackend}`);
|
log.info(`Backend storage for cache will be ${cacheBackend}`);
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
|
||||||
|
// Wait for onCacheSettingsReady() to be fully ready.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
µb.loadSelectedFilterLists().then(( ) => {
|
µb.loadSelectedFilterLists().then(( ) => {
|
||||||
log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`);
|
log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||||
}),
|
}),
|
||||||
µb.cacheStorage.get(
|
µb.cacheStorage.get(
|
||||||
{ compiledMagic: 0, selfieMagic: 0 }
|
{ compiledMagic: 0, selfieMagic: 0 }
|
||||||
).then(fetched => {
|
).then(fetched =>
|
||||||
log.info(`Cache magic numbers ready ${Date.now()-vAPI.T0} ms after launch`);
|
onCacheSettingsReady(fetched)
|
||||||
onCacheSettingsReady(fetched);
|
).then(( ) => {
|
||||||
|
log.info(`Integrity of cached data processed ${Date.now()-vAPI.T0} ms after launch`);
|
||||||
}),
|
}),
|
||||||
vAPI.storage.get(createDefaultProps()).then(fetched => {
|
vAPI.storage.get(createDefaultProps()).then(fetched => {
|
||||||
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
|
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||||
|
@ -737,7 +737,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
this.compiledFormatChanged === false &&
|
this.compiledFormatChanged === false &&
|
||||||
this.badLists.has(assetKey) === false
|
this.badLists.has(assetKey) === false
|
||||||
) {
|
) {
|
||||||
let compiledDetails = await this.assets.get(compiledPath);
|
const compiledDetails = await this.assets.get(compiledPath);
|
||||||
if ( compiledDetails.content !== '' ) {
|
if ( compiledDetails.content !== '' ) {
|
||||||
compiledDetails.assetKey = assetKey;
|
compiledDetails.assetKey = assetKey;
|
||||||
return compiledDetails;
|
return compiledDetails;
|
||||||
@ -763,19 +763,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
return { assetKey, content: '' };
|
return { assetKey, content: '' };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetching the raw content may cause the compiled content to be
|
const compiledContent =
|
||||||
// generated somewhere else in uBO, hence we try one last time to
|
this.compileFilters(rawDetails.content, { assetKey });
|
||||||
// fetch the compiled content in case it has become available.
|
this.assets.put(compiledPath, compiledContent);
|
||||||
const compiledDetails = await this.assets.get(compiledPath);
|
|
||||||
if ( compiledDetails.content === '' ) {
|
|
||||||
compiledDetails.content = this.compileFilters(rawDetails.content, {
|
|
||||||
assetKey
|
|
||||||
});
|
|
||||||
this.assets.put(compiledPath, compiledDetails.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
compiledDetails.assetKey = assetKey;
|
return { assetKey, content: compiledContent };
|
||||||
return compiledDetails;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user