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 into
main fromrefs/pull/1555/headopened - packages/db/tests/collection-subscriber-out-of-window-sse.test.ts lines 13 to 89@@ -0,0 +66,21 @@66+ sourceCollection.utils.write({67+ type: `delete`,68+ value: { id: `2`, value: 90 },69+ })70+ sourceCollection.utils.commit()71+72+ // Wait for loadNextItems to fetch the replacement73+ await new Promise((resolve) => setTimeout(resolve, 50))74+75+ results = Array.from(liveQueryCollection.values())76+ expect(results).toHaveLength(3)77+78+ // The replacement should be item 4 (value 70) — the next item from the79+ // BTree — NOT the out-of-window SSE insert (value 10).80+ expect(81+ results.map((r) => r.id),82+ `Expected item 4 (value 70) to replace deleted item 2, ` +83+ `not the out-of-window SSE insert (value 10). ` +84+ `Got: ${JSON.stringify(results.map((r) => ({ id: r.id, value: r.value })))}`,85+ ).toEqual([`1`, `3`, `4`])86+ })@@ -0,0 +54,21 @@54+ type: `insert`,55+ value: { id: `out-of-window`, value: 10 },56+ })57+ sourceCollection.utils.commit()58+59+ // Window should be unchanged60+ let results = Array.from(liveQueryCollection.values())61+ expect(results).toHaveLength(3)62+ expect(results.map((r) => r.id)).toEqual([`1`, `2`, `3`])63+64+ // Now delete one of the top-3 items65+ sourceCollection.utils.begin()66+ sourceCollection.utils.write({67+ type: `delete`,68+ value: { id: `2`, value: 90 },69+ })70+ sourceCollection.utils.commit()71+72+ // Wait for loadNextItems to fetch the replacement73+ await new Promise((resolve) => setTimeout(resolve, 50))74+
KyleAMathews(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
40278cd8-72df-468d-9972-a992f9a3a918📥 Commits
Reviewing files that changed from the base of the PR and between ae146bce3377e4292fe042e5ced4bb4059a04a47 and 7269fd4ab4cdb7d3e8264e280c8eb44393a2310f.
📒 Files selected for processing (1)
packages/db/tests/collection-subscriber-out-of-window-sse.test.ts📝 Walkthrough
Walkthrough#
sendChangesInRange now computes the ordered window (limit+offset) and a window boundary, filters incoming SSE changes to exclude out-of-window inserts (with exceptions), and uses the filtered set for tracking and downstream updates. Tests and a changeset entry validate and document the fix.
Changes#
Out-of-window SSE Insert Filtering
packages/db/src/query/live/collection-subscriber.ts,.changeset/fix-out-of-window-sse-filter.mdsendChangesInRangecomputes window size and boundary from the current largest value, filters incoming changes so non-inserts are always kept and inserts are kept only when already-sent, within window capacity, or at/after the boundary. Filtered changes are used for value tracking and downstream dispatch; release notes updated.packages/db/tests/collection-subscriber-out-of-window-sse.test.tsEstimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem#
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share