Repository navigation
Conversation
* Apply batched pulls sequentially and notify observers once per pull With _unsafeBatchPerCollection, all chunks were prepared up front and committed with Promise.all, so a failed chunk left an arbitrary subset applied (and the rest prepared in the cache), and observers re-fetched once per table and chunk. Chunks are now prepared and committed one after another, and the whole apply runs inside experimentalBatchNotifications. experimentalBatchNotifications now merges the changes made within it into a single notification instead of replaying one per batch. The docs now say that the option shrinks the native batch payload, not JS memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Clean up deleted records before applying changes, not concurrently With Promise.all, a failing destroyDeletedRecords rejected the apply (and let the sync Writer finish) while batches were still running. Those batches could then commit and notify outside the Writer and the notification scope. The steps now run one after another, in both the batched and the single-batch path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @joker-777, thank you for all the sync work, these PRs are really well explained! I maintain NitromelonDB, a maintained fork of WatermelonDB (New Architecture, Nitro Modules). This one applies there too: Our fork was rewritten in TypeScript (strict mode) to reduce the chance of bugs like this one slipping through, so I think the community would really benefit if you opened your PRs against it too. The code lives in If you don't have the time or would rather not, no worries at all, I'm happy to port it myself. Just let me know. Thanks a lot! |
With
_unsafeBatchPerCollection, pulled changes are applied in batches of up to 5000 records. This PR commits those batches one after another and sends observers one notification per pull.Changes
Promise.all. A failed batch stops the apply: earlier batches stay committed, and later ones are never prepared, so no record is left with a pending prepared statedatabase.experimentalBatchNotifications(), so observers fire once per pull instead of once per table and batchexperimentalBatchNotifications()now merges everything changed inside it into one notification: one call perexperimentalSubscribesubscriber and onecollection.changesemission per table. Before, it only deferred the per-batch notifications and replayed them one by oneSync/Frontend.mdand theSyncArgscomments) now say that the option shrinks the batch payload sent to the native side, not JS memory, and that it isn't transactionalTests
Databasetest covers merging notificationsVerification
sqlite-nodesuite was left out because better-sqlite3 does not build on the host's Node; this change does not touch the adapters).flow checkis clean, and ESLint is clean on the changed filesapplyRemote.jsand its tests in separate places. They merge into master together without conflicts, and Jest passes on the result🤖 Generated with Claude Code