Skip to content

Commit

Permalink
⚡️ Update contents caching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Jan 14, 2020
1 parent 6f075e8 commit 6cf84fe
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/models/root-store/setup-root-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]) {
Expand Down

0 comments on commit 6cf84fe

Please sign in to comment.