You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(db): batch D2 output callbacks to prevent duplicate key errors in joins (#1114)
* fix(db): batch D2 output callbacks to prevent duplicate key errors in joins
When D2's incremental join processes data, it can produce multiple outputs
during a single graph.run() iteration - first a partial join result, then
the full result plus a delete of the partial. Previously, each output
callback had its own begin()/commit() cycle, causing the second insert
for the same key to fail with DuplicateKeySyncError.
This fix:
- Accumulates all changes from output callbacks into a pendingChanges Map
- Flushes accumulated changes in a single transaction after each graph.run()
- Adds subscribedToAllCollections check to updateLiveQueryStatus() to ensure
markReady() is only called after the graph has processed data
- Properly types flushPendingChanges on SyncState to avoid type assertions
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* ci: apply automated fixes
* chore: add changeset for live query join fix
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* chore: update changeset to mention isReady fix
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* refactor: restore accumulateChanges helper function
Restore the accumulateChanges helper function instead of inlining its logic.
This improves code readability and maintainability by keeping the accumulation
logic in a separate, testable function.
Co-authored-by: Kevin <[email protected]>
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Kevin <[email protected]>
Fix `isReady()` returning `true` while `toArray()` returns empty results. The status now correctly waits until data has been processed through the graph before marking ready.
6
+
7
+
Also fix duplicate key errors when live queries use joins with custom `getKey` functions. D2's incremental join can produce multiple outputs for the same key during a single graph run; this change batches all outputs into a single transaction to prevent conflicts.
0 commit comments