Skip to content

Commit

Permalink
Ensure cache storage is selected before access
Browse files Browse the repository at this point in the history
Possibly related issue:
uBlockOrigin/uBlock-issues#2136

Also reported internally, steps to reproduce the issue fixed here:

- Open uBO's dashboard through 3-dot > Add-ons > uBO > Settings
- Bring forth "Filter lists" pane
  We want the tab to be already opened at next launch
- Quit Firefox for Android
- Launch Firefox for Android

Result:

Very long launch time, lists marked as out of date.
  • Loading branch information
gorhill committed Dec 10, 2023
1 parent 1849425 commit bfa28b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ const µBlock = { // jshint ignore:line
uiAccentStylesheet: '',
};

µBlock.isReadyPromise = new Promise(resolve => {
µBlock.isReadyResolve = resolve;
});

µBlock.domainFromHostname = domainFromHostname;
µBlock.hostnameFromURI = hostnameFromURI;

Expand Down
4 changes: 3 additions & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,9 @@ const onMessage = function(request, sender, callback) {
});

case 'getLists':
return getLists(callback);
return µb.isReadyPromise.then(( ) => {
getLists(callback);
});

case 'getLocalData':
return getLocalData().then(localData => {
Expand Down
18 changes: 8 additions & 10 deletions src/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ import {

/******************************************************************************/

// Load all: executed once.

(async ( ) => {
// >>>>> start of private scope

/******************************************************************************/

vAPI.app.onShutdown = ( ) => {
staticFilteringReverseLookup.shutdown();
io.updateStop();
Expand Down Expand Up @@ -312,10 +305,10 @@ const onHiddenSettingsReady = async ( ) => {
}

// Maybe override default cache storage
const cacheBackend = await cacheStorage.select(
µb.supportStats.cacheBackend = await cacheStorage.select(
µb.hiddenSettings.cacheStorageAPI
);
ubolog(`Backend storage for cache will be ${cacheBackend}`);
ubolog(`Backend storage for cache will be ${µb.supportStats.cacheBackend}`);
};

/******************************************************************************/
Expand Down Expand Up @@ -379,6 +372,9 @@ const createDefaultProps = ( ) => {

/******************************************************************************/

(async ( ) => {
// >>>>> start of async/await scope

try {
ubolog(`Start sequence of loading storage-based data ${Date.now()-vAPI.T0} ms after launch`);

Expand Down Expand Up @@ -506,5 +502,7 @@ if ( selfieIsValid ) {
}
ubolog(`All ready ${µb.supportStats.allReadyAfter} after launch`);

// <<<<< end of private scope
µb.isReadyResolve();

// <<<<< end of async/await scope
})();

0 comments on commit bfa28b9

Please sign in to comment.