Skip to content

Commit 8a28204

Browse files
committed
Track bucket priorities
1 parent 6241a18 commit 8a28204

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/powersync_core/lib/src/bucket_storage.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ class BucketStorage {
5353
var count = 0;
5454

5555
await writeTransaction((tx) async {
56+
final descriptions = [
57+
for (final MapEntry(:key, :value) in batch.descriptions.entries)
58+
{
59+
key: {'priority': value.priority},
60+
}
61+
];
62+
5663
for (var b in batch.buckets) {
5764
count += b.data.length;
5865
await _updateBucket2(
5966
tx,
6067
jsonEncode({
61-
'buckets': [b]
68+
'buckets': [b],
69+
'descriptions': descriptions,
6270
}));
6371
}
6472
// No need to flush - the data is not directly visible to the user either way.
@@ -352,8 +360,9 @@ class BucketState {
352360

353361
final class SyncDataBatch {
354362
final List<SyncBucketData> buckets;
363+
final Map<String, BucketDescription> descriptions;
355364

356-
SyncDataBatch(this.buckets);
365+
SyncDataBatch(this.buckets, this.descriptions);
357366
}
358367

359368
class SyncLocalDatabaseResult {

packages/powersync_core/lib/src/streaming_sync.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,9 @@ class StreamingSyncImplementation implements StreamingSync {
433433
await adapter.removeBuckets(diff.removedBuckets);
434434
adapter.setTargetCheckpoint(targetCheckpoint);
435435
case SyncBucketData():
436+
// TODO: Merge multiple of these into a single one...
436437
_updateStatus(downloading: true);
437-
await adapter.saveSyncData(SyncDataBatch([line]));
438+
await adapter.saveSyncData(SyncDataBatch([line], bucketMap));
438439
case StreamingSyncKeepalive():
439440
if (line.tokenExpiresIn == 0) {
440441
// Token expired already - stop the connection immediately

0 commit comments

Comments
 (0)