Skip to content
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: OP-sqlite write transaction single operation notification #461

Merged
merged 4 commits into from
Jan 8, 2025

Conversation

Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Jan 8, 2025

This PR addresses a timing issue in OPsqlite where the SQLite update hook triggers before the commit completes when performing single-write transactions (Resulting in ps_crud not being processed). As a result, nextCrudItem was returning undefined because the data was not yet committed at the time the hook fired.

Using react-native-quick-sqlite as reference, updates are now batched and only flushed after a write lock is released.

…ocessed. Batching update notifications per write lock.
Copy link

changeset-bot bot commented Jan 8, 2025

🦋 Changeset detected

Latest commit: 8441600

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/op-sqlite Minor

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

rkistner
rkistner previously approved these changes Jan 8, 2025
Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

I assume this would also affect regular watched queries?

@Chriztiaan
Copy link
Contributor Author

Chriztiaan commented Jan 8, 2025

Changes look good.

I assume this would also affect regular watched queries?

Using const { data: psCrud } = useQuery("Select * from ps_crud") initially I could see that it was stuck at 1, but its definitely becoming 0 now after being processed. I verified that powersync.watch also triggers with the expected results.

It does improve watched queries and the reactive query hooks.

@rkistner
Copy link
Contributor

rkistner commented Jan 8, 2025

I mean that if you had useQuery('select * from my_table'), you could potentially get outdated results before because of the same issue, and that should be fixed now.

@Chriztiaan
Copy link
Contributor Author

I mean that if you had useQuery('select * from my_table'), you could potentially get outdated results before because of the same issue, and that should be fixed now.

Correct - sorry I misunderstood. Updated the changeset entry to mention this.

@Chriztiaan Chriztiaan merged commit 181a9db into main Jan 8, 2025
6 checks passed
@Chriztiaan Chriztiaan deleted the fix/opsqlite-transaction-notifications branch January 8, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants