Tweak feed pagination

This commit is contained in:
Jonathan Staab 2023-03-06 13:53:23 -06:00
parent 10c556ae7b
commit 9c01895dbc
4 changed files with 14 additions and 8 deletions

View File

@ -37,7 +37,7 @@ const listen = ({relays, filter, onChunk = null, shouldProcess = true}) => {
}) })
} }
const load = ({relays, filter, onChunk = null, shouldProcess = true, timeout = 6000}) => { const load = ({relays, filter, onChunk = null, shouldProcess = true, timeout = 10_000}) => {
return new Promise(resolve => { return new Promise(resolve => {
const now = Date.now() const now = Date.now()
const done = new Set() const done = new Set()

View File

@ -149,13 +149,15 @@ export const getLastSync = (k, fallback = 0) => {
export class Cursor { export class Cursor {
until: number until: number
limit: number limit: number
constructor(limit = 50) { constructor(limit = 10) {
this.until = now() this.until = now()
this.limit = limit this.limit = limit
} }
getFilter() { getFilter() {
return { return {
until: this.until, // Add a buffer so we can avoid blowing past the most relevant time interval
// (just now) until after a few paginations.
until: this.until + timedelta(3, 'hours'),
// since: this.until - timedelta(8, 'hours'), // since: this.until - timedelta(8, 'hours'),
limit: this.limit, limit: this.limit,
} }
@ -166,12 +168,13 @@ export class Cursor {
// There are various edge cases: // There are various edge cases:
// - When we have zero events, there's nothing we can do, presumably we have everything. // - When we have zero events, there's nothing we can do, presumably we have everything.
// - Sometimes relays send us extremely old events. Use median to avoid too-large gaps // - Sometimes relays send us extremely old events. Use median to avoid too-large gaps
if (events.length > 1) { if (events.length > this.limit) {
const timestamps = sortBy(identity, pluck('created_at', events)) const timestamps = sortBy(identity, pluck('created_at', events))
const gaps = aperture(2, timestamps).map(([a, b]) => b - a) const gaps = aperture(2, timestamps).map(([a, b]) => b - a)
const gap = quantile(gaps, 0.1) const gap = quantile(gaps, 0.2)
this.until -= Math.round(gap * events.length) // Only paginate part of the way so we can avoid missing stuff
this.until -= Math.round(gap * events.length * 0.5)
} }
} }
} }

View File

@ -52,7 +52,10 @@
}) })
// Show replies grouped by parent whenever possible // Show replies grouped by parent whenever possible
return mergeParents(combined) const merged = mergeParents(combined)
// Drop the oldest 20% of notes since we often get pretty old stuff
return merged.slice(0, Math.ceil(merged.length * 0.8))
} }
const loadBufferedNotes = () => { const loadBufferedNotes = () => {

View File

@ -10,5 +10,5 @@
const shouldDisplay = e => isLike(e.content) const shouldDisplay = e => isLike(e.content)
</script> </script>
<Feed {relays} {filter} {shouldDisplay} parentsTimeout={3000} /> <Feed {relays} {filter} {shouldDisplay} parentsTimeout={10_000} />