Skip to content

Commit 013c2fb

Browse files
authored
Use case example for prioritized initial sync, using client parameters to sync specific tables first (#27)
* remove mac resource file * prioritized sync use cases when some tables need to sync first * simplify implimentation * Update syntax + fix typos Used parameter types support in diagnostics app to test syntax
1 parent 9b19b90 commit 013c2fb

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.DS_Store

-10 KB
Binary file not shown.
61.1 KB
Loading

mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
"usage/use-case-examples/infinite-scrolling",
211211
"usage/use-case-examples/offline-only-usage",
212212
"usage/use-case-examples/postgis",
213+
"usage/use-case-examples/prioritized-sync",
213214
"usage/use-case-examples/custom-write-checkpoints"
214215
]
215216
},
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Prioritized Sync"
3+
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 remaining tables in the background."
4+
---
5+
6+
## Overview
7+
8+
The general approach is as follows:
9+
10+
1. Define how many priority types you want - typically only two are needed: "high priority" and "the rest"
11+
2. Create a sync bucket for each priority type
12+
3. Use [client parameters](/usage/sync-rules/advanced-topics/client-parameters) to control which priorities you want the client to sync
13+
14+
## Example
15+
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)). Further, suppose we want the sync priority to behave as follows:
16+
17+
1. First, sync all the user's lists, enabling us to render the initial screen in the app
18+
2. Then, sync the user's todos
19+
20+
Below are the sync rules that will enable this:
21+
22+
```yaml
23+
bucket_definitions:
24+
# always sync high priority tables (first), in this case the user's lists
25+
high_priority:
26+
parameters: select id as list_id from lists where owner_id = token_parameters.user_id
27+
data:
28+
- select * from lists where id = bucket.list_id
29+
# sync any remaining tables, in this case todo items
30+
remaining:
31+
parameters: select id as list_id from lists where owner_id = token_parameters.user_id and (request.parameters() ->> 'remaining_tables' = true)
32+
data:
33+
- select * from todos where list_id = bucket.list_id
34+
```
35+
36+
It is recommended to set Client Parameters in the [Diagnostics App](https://github.com/powersync-ja/powersync-js/tree/main/tools/diagnostics-app) to verify functionality at this point:
37+
38+
<Frame>
39+
<img src="/images/usage/use-case-prioritized.png"/>
40+
</Frame>
41+
42+
If everything checks out, you can then proceed to implement the client parameter switching accordingly in your app.

0 commit comments

Comments
 (0)