Skip to content

Commit

Permalink
cursor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Dec 31, 2024
1 parent 077ea15 commit 130204e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/util/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ export abstract class FirehoseSubscriptionBase {

async run(subscriptionReconnectDelay: number) {
let handledEvents = 0
let lastSuccessfulCursor = (await this.getCursor()).cursor

this.jetstream = new Jetstream({
wantedCollections: Array.from(includedRecords.values()),
ws: WebSocket,
...(await this.getCursor()),
cursor: lastSuccessfulCursor,
})

this.jetstream.start()
Expand Down Expand Up @@ -62,15 +63,16 @@ export abstract class FirehoseSubscriptionBase {
})
}

handledEvents++
if (handledEvents >= 1000) {
this.updateCursor(posts.cursor).then(() => {
handledEvents = 0
})
if (lastSuccessfulCursor) this.updateCursor(lastSuccessfulCursor)
handledEvents = 0
}

if (posts.creates.length + posts.deletes.length > 0) {
this.handleEvent(posts)
this.handleEvent(posts).then(() => {
lastSuccessfulCursor = posts.cursor
handledEvents++
})
}
})
}
Expand Down

0 comments on commit 130204e

Please sign in to comment.