From 001b8c6166f634cc7f15ba111bf1e9b62c8ef409 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 11 Nov 2020 23:01:32 +0300 Subject: [PATCH] API.getAllStyles is actually faster with code untouched --- background/style-manager.js | 11 ++++++----- manage/manage.js | 4 ++-- popup/search-results.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index 1af60bef..0971b7af 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -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) { diff --git a/manage/manage.js b/manage/manage.js index 23b949f7..bc9cbd6a 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -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) { diff --git a/popup/search-results.js b/popup/search-results.js index 5558d958..0b35e39c 100755 --- a/popup/search-results.js +++ b/popup/search-results.js @@ -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)); }