-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Fix] Table change updates in write transactions #13
Conversation
src/DBListenerManager.ts
Outdated
private _writeTransactionActive: boolean; | ||
private updateBuffer: UpdateNotification[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpic: Use a consistent style for private
members. (Personally using a _
prefix feels unnecessary, because we are accessing it with this.
)
…es after write locks have completed or transaction has been committed.
Automated tests are currently a bit broken. The Android emulator seems to be freezing at random intervals. Sometimes before tests begin and sometimes during tests. |
This PR fixes an issue where table change updates registered via
registerUpdateHook
would trigger fromwriteTransaction
s before the changes have been committed or rolled back.If a client used the update hook to trigger a read from a read connection the updated data would not yet be visible. This causes inconsistent results when implementing watched queries.
This PR monitors the state of write transactions in order to emit update events only once the changes have been committed. This work is looseley based of the implementation here https://github.com/powersync-ja/sqlite_async.dart/blob/f994e165d5410c9ccca9a187de9c51fcedfd1182/lib/src/sqlite_connection_impl.dart#L310.
This PR also adds extra listeners which emit events for all table changes and write transaction events. This gives users access to table changes during transactions and allows for custom logic for deferring table change events during transactions.