-
Notifications
You must be signed in to change notification settings - Fork 9
Use case example for prioritized initial sync, using client parameters to sync specific tables first #27
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
Merged
Merged
Use case example for prioritized initial sync, using client parameters to sync specific tables first #27
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3295ed
remove mac resource file
kobiebotha 2f3538e
prioritized sync use cases
kobiebotha f206a29
simplify implimentation
kobiebotha 11191a0
Update syntax + fix typos
kobiebotha 8cdf589
Merge branch 'docs' into prioritized-sync
kobiebotha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "Prioritizied Sync" | ||
description: "In some scenarios, you may want to sync tables using different priorities. For example, you may want to sync a subset of all tables first to log a user in as fast as possible, then sync the reamining tables in the background." | ||
--- | ||
|
||
## Overview | ||
|
||
The general approach is as follows: | ||
|
||
1. Define how many priority types you want - typically only two are needed: "high priority" and "the rest" | ||
2. Create a sync bucket for each priority type | ||
3. Use [client parameters](/usage/sync-rules/advanced-topics/client-parameters) to control which priorities you want the client to sync | ||
|
||
## Example | ||
Suppose we have two tables: `lists` and `todos` (as per the standard todolist demo app [schema](/integration-guides/supabase-+-powersync#create-the-demo-database-schema)). We want the sync to behave as follows: | ||
|
||
1. First, sync all the user's lists, enabling us to render the initial screen in the app | ||
2. Then, sync the user's todos | ||
|
||
Below are the sync rules that will enable this: | ||
|
||
```yaml | ||
bucket_definitions: | ||
# sync high priority tables first, in this case the user's lists | ||
high_priority: | ||
parameters: select id as list_id from lists where owner_id = token_parameters.user_id and (request.parameters() ->> 'high_priority' = 'true') | ||
data: | ||
- select * from lists where id = bucket.list_id | ||
# sync any remaining tables, in this case todo items | ||
remaining: | ||
parameters: select id as list_id from lists where owner_id = token_parameters.user_id and (request.parameters() ->> 'remaining_tables' = 'true') | ||
kobiebotha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
data: | ||
- select * from todos where list_id = bucket.list_id | ||
``` | ||
|
||
It is recommended to set Client Parammeters in the [Diagnostics App](https://github.com/powersync-ja/powersync-js/tree/main/tools/diagnostics-app) to verify functionality at this point: | ||
|
||
<Frame> | ||
<img src="/images/usage/use-case-prioritized.png"/> | ||
</Frame> | ||
|
||
If everything checks out, you can then proceed to implement the client parameter switching accordingly in your app. |
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.
Uh oh!
There was an error while loading. Please reload this page.