Avoid fetching duplicate context, there seems to be an infinite loop that happens if we don't

This commit is contained in:
Jonathan Staab 2023-03-07 20:02:15 -06:00
parent 770ed5b286
commit 1dd9c6f791

View File

@ -21,12 +21,13 @@
let notes = []
let notesBuffer = []
const seen = new Set()
const since = now()
const maxNotes = 100
const cursor = new Cursor()
const processNewNotes = async newNotes => {
newNotes = user.muffle(newNotes)
newNotes = user.muffle(newNotes).filter(n => !seen.has(n.id))
if (shouldDisplay) {
newNotes = newNotes.filter(shouldDisplay)
@ -73,6 +74,10 @@
const chunk = sortBy(e => -e.created_at, await processNewNotes(newNotes))
const [bottom, top] = partition(e => e.created_at < since, chunk)
for (const note of chunk) {
seen.add(note.id)
}
// Slice new notes in case someone leaves the tab open for a long time
notes = uniqBy(prop('id'), notes.concat(bottom))
notesBuffer = top.concat(notesBuffer).slice(0, maxNotes)