Skip to content
Source
Sign inSign up
TanStack/db

fix(db): filter out-of-window SSE inserts in collection-subscriber #1555

Closedv-anton(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/1555/headopened

Showing 3 changed files with 227 additions and 2 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fix-out-of-window-sse-filter.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/db": patch
+---
+​
+fix(db): filter SSE inserts outside the current window before they reach D2
13 additions and 2 deletionspackages/db/src/query/live/collection-subscriber.tsModified
View file
@@ -248,15 +248,26 @@
// Use a holder to forward-reference subscription in the callback
const subscriptionHolder: { current?: CollectionSubscription } = {}
​
+ const windowSize = limit + offset
const sendChangesInRange = (
changes: Iterable<ChangeMessage<any, string | number>>,
) => {
const changesArray = Array.isArray(changes) ? changes : [...changes]
+ const windowBoundary = this.biggest
+ const relevant =
+ windowBoundary === undefined || windowSize === Infinity
+ ? changesArray
+ : changesArray.filter((change) => {
+ if (change.type !== `insert`) return true
+ if (this.sentToD2Keys.has(change.key)) return true
+ if (this.sentToD2Keys.size < windowSize) return true