Skip to content

Commit

Permalink
Track bucket priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Jan 29, 2025
1 parent 6241a18 commit 8a28204
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions packages/powersync_core/lib/src/bucket_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ class BucketStorage {
var count = 0;

await writeTransaction((tx) async {
final descriptions = [
for (final MapEntry(:key, :value) in batch.descriptions.entries)
{
key: {'priority': value.priority},
}
];

for (var b in batch.buckets) {
count += b.data.length;
await _updateBucket2(
tx,
jsonEncode({
'buckets': [b]
'buckets': [b],
'descriptions': descriptions,
}));
}
// No need to flush - the data is not directly visible to the user either way.
Expand Down Expand Up @@ -352,8 +360,9 @@ class BucketState {

final class SyncDataBatch {
final List<SyncBucketData> buckets;
final Map<String, BucketDescription> descriptions;

SyncDataBatch(this.buckets);
SyncDataBatch(this.buckets, this.descriptions);
}

class SyncLocalDatabaseResult {
Expand Down
3 changes: 2 additions & 1 deletion packages/powersync_core/lib/src/streaming_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ class StreamingSyncImplementation implements StreamingSync {
await adapter.removeBuckets(diff.removedBuckets);
adapter.setTargetCheckpoint(targetCheckpoint);
case SyncBucketData():
// TODO: Merge multiple of these into a single one...
_updateStatus(downloading: true);
await adapter.saveSyncData(SyncDataBatch([line]));
await adapter.saveSyncData(SyncDataBatch([line], bucketMap));
case StreamingSyncKeepalive():
if (line.tokenExpiresIn == 0) {
// Token expired already - stop the connection immediately
Expand Down

0 comments on commit 8a28204

Please sign in to comment.