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] Watched query updates #43

Merged
merged 4 commits into from
Jan 24, 2024
Merged

[Fix] Watched query updates #43

merged 4 commits into from
Jan 24, 2024

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Jan 23, 2024

Description

This PR fixes a bug where watched queries would sometimes fail to reflect updates from writeTransactions.

Watched queries don't update due to a race condition where the table change hook is fired before the changes have been committed. The read connections re-execute watched queries, but don't return the latest updates.

This builds off the work from powersync-ja/react-native-quick-sqlite#13 which adds new methods for receiving table change updates once changes have been committed to the DB.

The common DBAdapter interface has been updated in order to be compatible with the previous DB connection API for single table updates and the recently updated Batch updates.

Testing:

This was tested using the React Native Todolist app.

Before

With the current SDK certain operations only reflect in watched queries when refreshed. Initially Item 3 was deleted, but still remains on the view until a new item is created. There is also a large delay between creating the item and it appearing on screen. This is caused by the initial table update not firing at the correct time, the query is refreshed once the sync bucket is refreshed (due to syncing).

old_write_tx.mov

After

With the new updates all operations are reflected in the watched query in a timely manner.

new_write_tx.mov

TODO:

  • Update dev packages

rkistner
rkistner previously approved these changes Jan 23, 2024
@stevensJourney stevensJourney marked this pull request as ready for review January 24, 2024 09:44
@stevensJourney stevensJourney merged commit 6983121 into main Jan 24, 2024
1 check passed
@stevensJourney stevensJourney deleted the fix/watched-query-delay branch January 24, 2024 09:45
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.

2 participants