mirror of https://github.com/gorhill/uBlock.git
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];
|
||||
}
|
||||
if ( removedContent.length !== 0 ) {
|
||||
µBlock.cacheStorage.remove(removedContent);
|
||||
µBlock.cacheStorage.set({ assetCacheRegistry });
|
||||
await Promise.all([
|
||||
µBlock.cacheStorage.remove(removedContent),
|
||||
µBlock.cacheStorage.set({ assetCacheRegistry }),
|
||||
]);
|
||||
}
|
||||
for ( let i = 0; i < removedEntries.length; i++ ) {
|
||||
fireNotification(
|
||||
'after-asset-updated',
|
||||
{ assetKey: removedEntries[i] }
|
||||
);
|
||||
fireNotification('after-asset-updated', {
|
||||
assetKey: removedEntries[i]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -185,10 +185,12 @@ const onUserSettingsReady = function(fetched) {
|
|||
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1588916
|
||||
// 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 ) {
|
||||
µb.assets.remove(/^compiled\//);
|
||||
await µb.assets.remove(/^compiled\//);
|
||||
µb.compiledFormatChanged = true;
|
||||
µb.selfieIsInvalid = true;
|
||||
}
|
||||
|
@ -292,15 +294,18 @@ try {
|
|||
);
|
||||
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([
|
||||
µb.loadSelectedFilterLists().then(( ) => {
|
||||
log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
}),
|
||||
µb.cacheStorage.get(
|
||||
{ compiledMagic: 0, selfieMagic: 0 }
|
||||
).then(fetched => {
|
||||
log.info(`Cache magic numbers ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
onCacheSettingsReady(fetched);
|
||||
).then(fetched =>
|
||||
onCacheSettingsReady(fetched)
|
||||
).then(( ) => {
|
||||
log.info(`Integrity of cached data processed ${Date.now()-vAPI.T0} ms after launch`);
|
||||
}),
|
||||
vAPI.storage.get(createDefaultProps()).then(fetched => {
|
||||
log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`);
|
||||
|
|
|
@ -737,7 +737,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
this.compiledFormatChanged === false &&
|
||||
this.badLists.has(assetKey) === false
|
||||
) {
|
||||
let compiledDetails = await this.assets.get(compiledPath);
|
||||
const compiledDetails = await this.assets.get(compiledPath);
|
||||
if ( compiledDetails.content !== '' ) {
|
||||
compiledDetails.assetKey = assetKey;
|
||||
return compiledDetails;
|
||||
|
@ -763,19 +763,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
return { assetKey, content: '' };
|
||||
}
|
||||
|
||||
// Fetching the raw content may cause the compiled content to be
|
||||
// generated somewhere else in uBO, hence we try one last time to
|
||||
// fetch the compiled content in case it has become available.
|
||||
const compiledDetails = await this.assets.get(compiledPath);
|
||||
if ( compiledDetails.content === '' ) {
|
||||
compiledDetails.content = this.compileFilters(rawDetails.content, {
|
||||
assetKey
|
||||
});
|
||||
this.assets.put(compiledPath, compiledDetails.content);
|
||||
}
|
||||
const compiledContent =
|
||||
this.compileFilters(rawDetails.content, { assetKey });
|
||||
this.assets.put(compiledPath, compiledContent);
|
||||
|
||||
compiledDetails.assetKey = assetKey;
|
||||
return compiledDetails;
|
||||
return { assetKey, content: compiledContent };
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue