Remove buffer from cursor

This commit is contained in:
Jonathan Staab 2023-04-26 10:17:08 -05:00
parent 51a90fe9a7
commit f7231a757b

View File

@ -115,7 +115,6 @@ class Cursor {
delta?: number
until: Record<string, number>
since: number
buffer: Array<MyEvent>
seen: Set<string>
constructor({relays, limit = 20, delta = undefined}) {
this.relays = relays
@ -123,7 +122,6 @@ class Cursor {
this.delta = delta
this.until = fromPairs(relays.map(({url}) => [url, now()]))
this.since = delta ? now() : 0
this.buffer = []
this.seen = new Set()
}
async loadPage({filter, onChunk}) {
@ -138,21 +136,8 @@ class Cursor {
await Promise.all(
this.getGroupedRelays()
.filter(([until]) => until > this.since)
.map(([until, relays]) => {
// If the relay gave us a bunch of stuff outside our window, hold on to
// it until it's needed, and don't request it again. Don't add since to
// our filter so we can paginate without stalling.
this.buffer = this.buffer.filter(event => {
if (event.created_at > this.since) {
onEvent(event)
return false
}
return true
})
return load({
.map(([until, relays]) =>
load({
relays: relays,
filter: ensurePlural(filter).map(
mergeLeft({until, limit: this.limit, since: this.since})
@ -169,15 +154,11 @@ class Cursor {
this.seen.add(event.id)
if (event.created_at < this.since) {
this.buffer.push(event)
} else {
onEvent(event)
}
onEvent(event)
}
},
})
})
)
)
// If we got zero results for any relays, they have nothing for the given window,