mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-22 21:57:47 +02:00
Code review implementation of cacheStorage.clear()
Possibly related issue: - https://old.reddit.com/r/firefox/comments/b3u4nj/what_is_the_estimated_time_period_for_reviewing_a/ @gwarser has been able to reproduce at will, while I have been unable to reproduce at all. The change here is to clear the content of the database instead of outright deleting it before restoring backed up settings.
This commit is contained in:
parent
da9e3f29b8
commit
f62d866b36
2 changed files with 23 additions and 19 deletions
|
@ -211,10 +211,7 @@
|
||||||
if ( ev.oldVersion === 1 ) { return; }
|
if ( ev.oldVersion === 1 ) { return; }
|
||||||
try {
|
try {
|
||||||
const db = ev.target.result;
|
const db = ev.target.result;
|
||||||
const table = db.createObjectStore(
|
db.createObjectStore(STORAGE_NAME, { keyPath: 'key' });
|
||||||
STORAGE_NAME,
|
|
||||||
{ keyPath: 'key' }
|
|
||||||
);
|
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
req.onerror();
|
req.onerror();
|
||||||
}
|
}
|
||||||
|
@ -422,15 +419,18 @@
|
||||||
if ( typeof callback !== 'function' ) {
|
if ( typeof callback !== 'function' ) {
|
||||||
callback = noopfn;
|
callback = noopfn;
|
||||||
}
|
}
|
||||||
disconnect();
|
getDb().then(db => {
|
||||||
try {
|
let transaction = db.transaction(STORAGE_NAME, 'readwrite');
|
||||||
const req = indexedDB.deleteDatabase(STORAGE_NAME);
|
transaction.oncomplete =
|
||||||
req.onsuccess = req.onerror = ( ) => {
|
transaction.onerror =
|
||||||
|
transaction.onabort = ( ) => {
|
||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
} catch(ex) {
|
transaction.objectStore(STORAGE_NAME).clear();
|
||||||
|
}).catch(reason => {
|
||||||
|
console.info(`cacheStorage.clearDb() failed: ${reason}`);
|
||||||
callback();
|
callback();
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return getDb().then(db => {
|
return getDb().then(db => {
|
||||||
|
|
|
@ -799,17 +799,21 @@ var backupUserData = function(callback) {
|
||||||
µb.assets.get(µb.userFiltersPath, onUserFiltersReady);
|
µb.assets.get(µb.userFiltersPath, onUserFiltersReady);
|
||||||
};
|
};
|
||||||
|
|
||||||
var restoreUserData = function(request) {
|
const restoreUserData = function(request) {
|
||||||
var userData = request.userData;
|
const userData = request.userData;
|
||||||
|
|
||||||
var restart = function() {
|
const restart = function() {
|
||||||
vAPI.app.restart();
|
vAPI.app.restart();
|
||||||
};
|
};
|
||||||
|
|
||||||
var onAllRemoved = function() {
|
let countdown = 2;
|
||||||
|
|
||||||
|
const onAllRemoved = function() {
|
||||||
|
countdown -= 1;
|
||||||
|
if ( countdown !== 0 ) { return; }
|
||||||
µBlock.saveLocalSettings();
|
µBlock.saveLocalSettings();
|
||||||
vAPI.storage.set(userData.userSettings);
|
vAPI.storage.set(userData.userSettings);
|
||||||
var hiddenSettings = userData.hiddenSettings;
|
let hiddenSettings = userData.hiddenSettings;
|
||||||
if ( hiddenSettings instanceof Object === false ) {
|
if ( hiddenSettings instanceof Object === false ) {
|
||||||
hiddenSettings = µBlock.hiddenSettingsFromString(
|
hiddenSettings = µBlock.hiddenSettingsFromString(
|
||||||
userData.hiddenSettingsString || ''
|
userData.hiddenSettingsString || ''
|
||||||
|
@ -840,7 +844,7 @@ var restoreUserData = function(request) {
|
||||||
|
|
||||||
// If we are going to restore all, might as well wipe out clean local
|
// If we are going to restore all, might as well wipe out clean local
|
||||||
// storage
|
// storage
|
||||||
µb.cacheStorage.clear();
|
µb.cacheStorage.clear().then(( ) => { onAllRemoved(); });
|
||||||
vAPI.storage.clear(onAllRemoved);
|
vAPI.storage.clear(onAllRemoved);
|
||||||
vAPI.localStorage.removeItem('immediateHiddenSettings');
|
vAPI.localStorage.removeItem('immediateHiddenSettings');
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue