Open
Conversation
|
Hi! I'm the It looks like you correctly set up a CI job that uses the autofix.ci GitHub Action, but the autofix.ci GitHub App has not been installed for this repository. This means that autofix.ci unfortunately does not have the permissions to fix this pull request. If you are the repository owner, please install the app and then restart the CI workflow! 😃 |
on-demand Sync Mode
ca40064 to
a41deb1
Compare
on-demand Sync Modeon-demand Sync Mode
on-demand Sync Modeon-demand Sync Mode
Collaborator
stevensJourney
left a comment
There was a problem hiding this comment.
The implementation looks good to me. Pending mutations is the only possible concern I can think of.
…escape internal management of the destination table. Allows us to drop the need for mutexes.
stevensJourney
approved these changes
Mar 5, 2026
…on_id. Using createDestination table helper.
…f having dedicated unload implementation.
benitav
reviewed
Mar 10, 2026
| @@ -0,0 +1,223 @@ | |||
| ## Calling sync streams automatically | |||
There was a problem hiding this comment.
Suggested change
| ## Calling sync streams automatically | |
| ## Calling Sync Streams automatically |
benitav
reviewed
Mar 10, 2026
| @@ -0,0 +1,223 @@ | |||
| ## Calling sync streams automatically | |||
|
|
|||
| For the these examples we assuming the follow sync stream exists: | |||
There was a problem hiding this comment.
Suggested change
| For the these examples we assuming the follow sync stream exists: | |
| For the these examples we are assuming the follow Sync Streams exists: |
benitav
reviewed
Mar 10, 2026
| powerSyncCollectionOptions({ | ||
| database: db, | ||
| table: AppSchema.props.todos, | ||
| syncMode: `eager`, |
There was a problem hiding this comment.
I noticed sometimes we use backticks for syncMode, sometime single quotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On-demand collection sync
This PR introduces an
on-demandsync mode for collections, building on top of the existing eager implementation.Instead of copying the entire source table into the collection upfront,
on-demandmode only syncs the subset of data relevant to active live queries. We achieve this by implementing theloadSubsetandunloadSubsethandlers that TanstackDB calls when live queries are registered or deregistered.How it works:
When
loadSubsetis called, we receive the query's where expression from the TanstackDB query API. We compile this down to a SQLiteWHEREclause (taking a comparable approach to what Electric does for PostgreSQL), and the PoC covers every where expression supported by the TanstackDB query API. The compiled expression is added to our set of tracked expressions, and we refresh the diff trigger with all accumulated expressions OR'd together.unloadSubsetremoves the expression and refreshes the diff trigger accordingly.The existing diff trigger and tracking table infrastructure is reused - the only difference is that the trigger now watches a constrained dataset defined by the combined query expressions rather than the full source table.
Stale data eviction on unload
Since where expressions are OR'd together, adding queries only ever widens the synced dataset. When a query is deregistered, however, its data may become stale since it's no longer actively synced. To handle this,
unloadSubsetevicts entries from the collection that match the departing query but not any of the remaining queries, effectively:SELECT id FROM ${viewName} WHERE (${departingWhereSQL}) AND NOT (${remainingWhereSQL}).Future Work (red area)
Map out the possible queries we can expect with the TanstackDB, and map what it would look like if we derived sync stream information from the predicates. This would allow us to help constrain/optimise data synced to from the PowerSync service to the local PowerSync SQLite data, which would have a potential effect of making the client side
on-demandsync faster.