-
Notifications
You must be signed in to change notification settings - Fork 49
feat(common, node): best effort to emit BatchedUpdateNotification
so clients know the rowid that changed, not just which table
#646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 29f6253 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Without having looked at the implementation in detail yet, I think this is pretty neat. However, could you share some more details or a use-case that requires access to the rowid? I can't come up with one at the top of my head, is this primarily for more fine-grained update tracking in queries? (because we're also working on that with #614). With PowerSync, isn't the generated |
I'm wanting to know when sqlite rows are updated by PowerSync when it pulls data from the postgres buckets. I started by looking at the So I next looked at the I dug deeper and saw that the PowerSync sqlite extensions provide a Seeing that the SDK already defines the UpdateNotification interface with those properties from the update hook event, and that the OPSQLiteConnection publishes data matching that interface, I thought that it may be an oversight that the BetterSQLite3DBAdapter only published the table names. So the goal of this PR is to get the BetterSQLite3DBAdapter to publish the update hook data like the OPSLiteConnection does so that the PowerSyncDatabase onChange* methods can publish them, too.
Correct. The ID column is preferred. The ROWID column does change as rows are deleted/inserted, so it is not stable. But it's better than nothing at the moment for my use case. Because the PowerSync team's effort is focused on #614 and we've noted that long-term relying on ROWID is not ideal, I'll refactor this PR to make the least amount of changes I can to bubble up the update hook data to minimally conform to the existing UpdateNotification interface and OPSQLiteConnection behavior. If you all choose to accept the change, great, if not, I still need to use it in my project which I can do via Thanks! |
…Executor can run them. Ensure resources and listeners are disposed.
…e in the updateHook rather than emitting a partial object.
733d9b7
to
ce67260
Compare
@simolus3 I've refactored the approach to mitigate memory leaks and race condition that could lead to missed updates, would appreciate your follow up review at your convenience |
Background
For my use case I need to know which rows have changed when the PowerSync client downloads data from the upstream postgres database.
The
watchQuery*
andonChange*
client methods do not provide that granular of data. ThewatchQuery*
methods simply rerun the query returning all records rather than the ones that changed (to be fixed in #614). TheonChange*
methods only indicate the table names that had changes.The PowerSync sqlite extension's
updateHook
method emits a tuple of database name, table name, DML operation, and rowid when a change occurs on a table. This hook provides the data emitted by theonChange*
method but the node SDK is only emitting the table names, unlike the OPSQLiteConnection which emits a full BatchedUpdateNotification object.Problems
ControlledExecutor
may miss table updates if the updates arrive quicker than the executor can run them because the executor keeps at most one call-to-run queued.onChangeWithCallback
has memory leak because does not remove the abort signal's event listener.Changes
packages/common
WatchOnChangeEvent
interface to addupdate: BatchedUpdateNotification
ControlledExecutor
with asetInterval
to flush updates at most everythrottleMs
DisposeManager
class to centralize logic around calling disposers in order and managing event listeners on abort signalspackages/node
BetterSQLite3DBAdapter.ts
to emit a fullBatchedUpdateNotification
object rather than a partial that only indicated the table namesSqliteWorker.ts
to emit a fullUpdateNotification
object based on data from theupdateHook
instead of only the table name