IndexedDB getAll to read all styles in one op
Available since Chrome 48, FF44 (or FF27+ using dom.indexedDB.experimental flag)
This commit is contained in:
parent
f4e689721a
commit
f256f558dc
20
storage.js
20
storage.js
|
@ -20,7 +20,7 @@ function getDatabase(ready, error) {
|
|||
|
||||
// Let manage/popup/edit reuse background page variables
|
||||
// Note, only "var"-declared variables are visible from another extension page
|
||||
var cachedStyles = ((bg) => bg && bg.cache || {
|
||||
var cachedStyles = ((bg) => bg && bg.cachedStyles || {
|
||||
bg,
|
||||
list: null,
|
||||
noCode: null,
|
||||
|
@ -67,23 +67,16 @@ function getStyles(options, callback) {
|
|||
getDatabase(db => {
|
||||
const tx = db.transaction(['styles'], 'readonly');
|
||||
const os = tx.objectStore('styles');
|
||||
const all = [];
|
||||
os.openCursor().onsuccess = event => {
|
||||
const cursor = event.target.result;
|
||||
if (cursor) {
|
||||
const s = cursor.value;
|
||||
s.id = cursor.key;
|
||||
all.push(cursor.value);
|
||||
cursor.continue();
|
||||
} else {
|
||||
cachedStyles.list = all;
|
||||
os.getAll().onsuccess = event => {
|
||||
cachedStyles.list = event.target.result || [];
|
||||
cachedStyles.noCode = [];
|
||||
for (let style of all) {
|
||||
cachedStyles.byId.clear();
|
||||
for (let style of cachedStyles.list) {
|
||||
const noCode = getStyleWithNoCode(style);
|
||||
cachedStyles.noCode.push(noCode);
|
||||
cachedStyles.byId.set(style.id, {style, noCode});
|
||||
}
|
||||
//console.log('%s getStyles %s, invoking cached callbacks: %o', (performance.now() - t0).toFixed(1), JSON.stringify(options), cache.mutex.onDone.map(e => JSON.stringify(e.options)))
|
||||
//console.log('%s getStyles %s, invoking cached callbacks: %o', (performance.now() - t0).toFixed(1), JSON.stringify(options), cachedStyles.mutex.onDone.map(e => JSON.stringify(e.options)))
|
||||
try{
|
||||
callback(filterStyles(options));
|
||||
} catch(e){
|
||||
|
@ -95,7 +88,6 @@ function getStyles(options, callback) {
|
|||
callback(filterStyles(options));
|
||||
}
|
||||
cachedStyles.mutex.onDone = [];
|
||||
}
|
||||
};
|
||||
}, null);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user