From 6cf84fe1a25d6a57a73bce779e3d93cfc5d6e790 Mon Sep 17 00:00:00 2001 From: "Ng Wing Tat, David" Date: Tue, 14 Jan 2020 19:34:08 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Update=20contents=20cachin?= =?UTF-8?q?g=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/root-store/setup-root-store.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/root-store/setup-root-store.ts b/app/models/root-store/setup-root-store.ts index 4ffe439f7..9cd2f9dc6 100644 --- a/app/models/root-store/setup-root-store.ts +++ b/app/models/root-store/setup-root-store.ts @@ -88,7 +88,7 @@ export async function setupRootStore() { onSnapshot( rootStore, ({ - /* eslint-disable @typescript-eslint/no-unused-vars */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars navigationStore, readerStore: { contents, @@ -99,18 +99,24 @@ export async function setupRootStore() { bookmarkList, }, ...snapshot - /* eslint-enable @typescript-eslint/no-unused-vars */ }) => { - const bookmarkURLs = new Set(bookmarkList) - const [bookmarks, restContents] = partition(c => bookmarkURLs.has(c.url), Object.values(contents)) + const toBePersistedContentURLs = new Set([ + ...bookmarkList, + ...featuredList, + ...followedList.slice(0, 20), + ]) + const [toBePersistedContents, restContents] = partition( + c => toBePersistedContentURLs.has(c.url), + Object.values(contents) + ) const snContents = {} const snCreators = {} restContents .sort((a, b) => b.timestamp - a.timestamp) // Cache 1,000 contents at max and .slice(0, 1000) - // cache all bookmarks - .concat(bookmarks) + // Cache preferred contents + .concat(toBePersistedContents) .forEach(c => { snContents[c.url] = c if (creators[c.creator]) {