API.getAllStyles is actually faster with code untouched
This commit is contained in:
parent
e5ad9fce46
commit
001b8c6166
|
@ -12,6 +12,8 @@ script would try to fetch the new code.
|
||||||
The live preview feature relies on `runtime.connect` and `port.onDisconnect`
|
The live preview feature relies on `runtime.connect` and `port.onDisconnect`
|
||||||
to cleanup the temporary code. See /edit/live-preview.js.
|
to cleanup the temporary code. See /edit/live-preview.js.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @type {styleManager} */
|
||||||
const styleManager = (() => {
|
const styleManager = (() => {
|
||||||
const preparing = prepare();
|
const preparing = prepare();
|
||||||
|
|
||||||
|
@ -65,9 +67,9 @@ const styleManager = (() => {
|
||||||
|
|
||||||
handleLivePreviewConnections();
|
handleLivePreviewConnections();
|
||||||
|
|
||||||
return Object.assign({
|
return Object.assign(/** @namespace styleManager */{
|
||||||
compareRevision
|
compareRevision
|
||||||
}, ensurePrepared({
|
}, ensurePrepared(/** @namespace styleManager */{
|
||||||
get,
|
get,
|
||||||
getByUUID,
|
getByUUID,
|
||||||
getSectionsByUrl,
|
getSectionsByUrl,
|
||||||
|
@ -135,9 +137,8 @@ const styleManager = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllStyles(noCode = false) {
|
function getAllStyles() {
|
||||||
const datas = [...styles.values()].map(s => s.data);
|
return [...styles.values()].map(s => s.data);
|
||||||
return noCode ? datas.map(getStyleWithNoCode) : datas;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareRevision(rev1, rev2) {
|
function compareRevision(rev1, rev2) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ const OWN_ICON = chrome.runtime.getManifest().icons['16'];
|
||||||
const handleEvent = {};
|
const handleEvent = {};
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
API.getAllStyles(true),
|
API.getAllStyles(),
|
||||||
// FIXME: integrate this into filter.js
|
// FIXME: integrate this into filter.js
|
||||||
router.getSearch('search') && API.searchDB({query: router.getSearch('search')}),
|
router.getSearch('search') && API.searchDB({query: router.getSearch('search')}),
|
||||||
waitForSelector('#installed'), // needed to avoid flicker due to an extra frame and layout shift
|
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');
|
let iconsMissing = iconsEnabled && !$('.applies-to img');
|
||||||
if (changed.enabled || (iconsMissing && !createStyleElement.parts)) {
|
if (changed.enabled || (iconsMissing && !createStyleElement.parts)) {
|
||||||
installed.textContent = '';
|
installed.textContent = '';
|
||||||
API.getAllStyles(true).then(showStyles);
|
API.getAllStyles().then(showStyles);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (changed.targets) {
|
if (changed.targets) {
|
||||||
|
|
|
@ -181,7 +181,7 @@ window.addEventListener('showStyles:done', () => {
|
||||||
results = await search({retry});
|
results = await search({retry});
|
||||||
}
|
}
|
||||||
if (results.length) {
|
if (results.length) {
|
||||||
const installedStyles = await API.getAllStyles(true);
|
const installedStyles = await API.getAllStyles();
|
||||||
const allUsoIds = new Set(installedStyles.map(calcUsoId));
|
const allUsoIds = new Set(installedStyles.map(calcUsoId));
|
||||||
results = results.filter(r => !allUsoIds.has(r.i));
|
results = results.filter(r => !allUsoIds.has(r.i));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user