From 69e101aa3e0504e7f19ae29e61e4f579d7df8752 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Thu, 25 Jan 2024 03:42:01 +0900 Subject: [PATCH] Use sidebar cache correctly --- webextensions/background/background-cache.js | 2 +- webextensions/sidebar/sidebar-cache.js | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/webextensions/background/background-cache.js b/webextensions/background/background-cache.js index e6f8d9734..6986988b8 100644 --- a/webextensions/background/background-cache.js +++ b/webextensions/background/background-cache.js @@ -533,7 +533,7 @@ Tab.onHidden.addListener(tab => { browser.runtime.onMessage.addListener((message, _sender) => { switch (message && message.type) { case Constants.kCOMMAND_GET_ON_MEMORY_CACHE: - return mCaches[message.key]; + return Promise.resolve(mCaches[message.key]); case Constants.kCOMMAND_SET_ON_MEMORY_CACHE: if (message.value) diff --git a/webextensions/sidebar/sidebar-cache.js b/webextensions/sidebar/sidebar-cache.js index 993e05a90..b6365fa67 100644 --- a/webextensions/sidebar/sidebar-cache.js +++ b/webextensions/sidebar/sidebar-cache.js @@ -83,18 +83,13 @@ export async function tryPreload(tab = null) { } async function preload(tab) { - const cache = await Promise.all([ - browser.sessions.getWindowValue(tab.windowId, Constants.kWINDOW_STATE_CACHED_SIDEBAR), - browser.sessions.getWindowValue(tab.windowId, Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY), - browser.sessions.getWindowValue(tab.windowId, Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY), - browser.sessions.getTabValue(tab.id, Constants.kWINDOW_STATE_CACHED_SIDEBAR), - browser.sessions.getTabValue(tab.id, Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY), - browser.sessions.getTabValue(tab.id, Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY) - ]).catch(ApiTabs.createErrorSuppressor()); - if (!cache) - return; - mPreloadedCaches.set(`window${tab.windowId}`, cache.slice(0, 2)); - mPreloadedCaches.set(`tab${tab.id}`, cache.slice(3, 5)); + mTargetWindow = tab.windowId; + const cache = await MetricsData.addAsync('preload: reading window cache', Promise.all([ + getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR), + getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY), + getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY), + ]).catch(ApiTabs.createErrorSuppressor())); + mPreloadedCaches.set(`window${mTargetWindow}`, cache); } export async function getEffectiveWindowCache(options = {}) {