Skip to content

Commit

Permalink
Store very large HTML as a blob #3434
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 25, 2024
1 parent dc3b45b commit 7258f38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions webextensions/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ export const kWINDOW_STATE_SUBPANEL_HEIGHT = 'subpanel-height';
export const kWINDOW_STATE_SUBPANEL_EFFECTIVE_HEIGHT = 'subpanel-effective-height';
export const kWINDOW_STATE_CACHED_TABS = 'cached-tabs';
export const kWINDOW_STATE_CACHED_SIDEBAR = 'cached-sidebar-contents';
export const kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS = 'cached-sidebar-contents:contents';
export const kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY = 'cached-sidebar-contents:tabs-dirty';
export const kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY = 'cached-sidebar-contents:collapsed-dirty';

export const kCACHE_KEYS = [
kWINDOW_STATE_CACHED_TABS,
kWINDOW_STATE_CACHED_SIDEBAR,
kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS,
kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY,
kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY,
];
Expand Down
17 changes: 15 additions & 2 deletions webextensions/sidebar/sidebar-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async function preload(tab) {
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_CONTENTS),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY),
]).catch(ApiTabs.createErrorSuppressor()));
Expand All @@ -97,6 +98,7 @@ export async function getEffectiveWindowCache(options = {}) {
log('getEffectiveWindowCache: start');
cancelReservedUpdateCachedTabbar(); // prevent to break cache before loading
let cache;
let cachedContents;
let cachedSignature;
let actualSignature;
await Promise.all([
Expand All @@ -109,12 +111,19 @@ export async function getEffectiveWindowCache(options = {}) {
// [cache, const tabsDirty, const collapsedDirty] = await Promise.all([
let tabsDirty, collapsedDirty;
const preloadedCache = mPreloadedCaches.get(`window${mLastWindowCacheOwner.windowId}`);
[cache, tabsDirty, collapsedDirty] = preloadedCache || await MetricsData.addAsync('getEffectiveWindowCache: reading window cache', Promise.all([
[cache, cachedContents, tabsDirty, collapsedDirty] = preloadedCache || await MetricsData.addAsync('getEffectiveWindowCache: reading window cache', Promise.all([
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY)
]));
mPreloadedCaches.clear();
if (cache && cache.tabbar && cachedContents) {
const contents = await cachedContents.text();
const versionPart = contents.match(/^version=(\d+)\n/);
if (versionPart && versionPart[1] == cache.version)
cache.tabbar.contents = contents.replace(/^version=(\d+)\n/, '');
}
cachedSignature = cache && cache.signature;
log(`getEffectiveWindowCache: got from the owner `, mLastWindowCacheOwner, {
cachedSignature, cache, tabsDirty, collapsedDirty
Expand Down Expand Up @@ -467,6 +476,7 @@ function clearWindowCache() {
if (!configs.persistCachedTree)
clearPersistentWindowCache();
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR);
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS);
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY);
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY);
}
Expand Down Expand Up @@ -557,13 +567,16 @@ async function updateCachedTabbar() {
updateWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR, {
version: kCONTENTS_VERSION,
tabbar: {
contents: SidebarTabs.wholeContainer.innerHTML,
style: mTabBar.getAttribute('style'),
pinnedTabsCount: Tab.getPinnedTabs(mTargetWindow).length
},
indent: Indent.getCacheInfo(),
signature
});
updateWindowCache(
Constants.kWINDOW_STATE_CACHED_SIDEBAR_CONTENTS,
new Blob([`version=${kCONTENTS_VERSION}\n${SidebarTabs.wholeContainer.innerHTML}`])
);
}


Expand Down

0 comments on commit 7258f38

Please sign in to comment.