API.getAllStyles is actually faster with code untouched

This commit is contained in:
tophf 2020-11-11 23:01:32 +03:00
parent e5ad9fce46
commit 001b8c6166
3 changed files with 9 additions and 8 deletions

View File

@ -12,6 +12,8 @@ script would try to fetch the new code.
The live preview feature relies on `runtime.connect` and `port.onDisconnect`
to cleanup the temporary code. See /edit/live-preview.js.
*/
/** @type {styleManager} */
const styleManager = (() => {
const preparing = prepare();
@ -65,9 +67,9 @@ const styleManager = (() => {
handleLivePreviewConnections();
return Object.assign({
return Object.assign(/** @namespace styleManager */{
compareRevision
}, ensurePrepared({
}, ensurePrepared(/** @namespace styleManager */{
get,
getByUUID,
getSectionsByUrl,
@ -135,9 +137,8 @@ const styleManager = (() => {
}
}
function getAllStyles(noCode = false) {
const datas = [...styles.values()].map(s => s.data);
return noCode ? datas.map(getStyleWithNoCode) : datas;
function getAllStyles() {
return [...styles.values()].map(s => s.data);
}
function compareRevision(rev1, rev2) {

View File

@ -47,7 +47,7 @@ const OWN_ICON = chrome.runtime.getManifest().icons['16'];
const handleEvent = {};
Promise.all([
API.getAllStyles(true),
API.getAllStyles(),
// FIXME: integrate this into filter.js
router.getSearch('search') && API.searchDB({query: router.getSearch('search')}),
waitForSelector('#installed'), // needed to avoid flicker due to an extra frame and layout shift
@ -666,7 +666,7 @@ function switchUI({styleOnly} = {}) {
let iconsMissing = iconsEnabled && !$('.applies-to img');
if (changed.enabled || (iconsMissing && !createStyleElement.parts)) {
installed.textContent = '';
API.getAllStyles(true).then(showStyles);
API.getAllStyles().then(showStyles);
return;
}
if (changed.targets) {

View File

@ -181,7 +181,7 @@ window.addEventListener('showStyles:done', () => {
results = await search({retry});
}
if (results.length) {
const installedStyles = await API.getAllStyles(true);
const installedStyles = await API.getAllStyles();
const allUsoIds = new Set(installedStyles.map(calcUsoId));
results = results.filter(r => !allUsoIds.has(r.i));
}