@@ -33,12 +33,11 @@ class BucketStorage {
3333
3434 Future <List <BucketState >> getBucketStates () async {
3535 final rows = await select (
36- 'SELECT name as bucket, priority, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0 AND name != \'\$ local\' ' );
36+ 'SELECT name as bucket, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0 AND name != \'\$ local\' ' );
3737 return [
3838 for (var row in rows)
3939 BucketState (
4040 bucket: row['bucket' ],
41- priority: row['priority' ],
4241 opId: row['op_id' ],
4342 )
4443 ];
@@ -53,20 +52,12 @@ class BucketStorage {
5352 var count = 0 ;
5453
5554 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-
6355 for (var b in batch.buckets) {
6456 count += b.data.length;
6557 await _updateBucket2 (
6658 tx,
6759 jsonEncode ({
6860 'buckets' : [b],
69- 'descriptions' : descriptions,
7061 }));
7162 }
7263 // No need to flush - the data is not directly visible to the user either way.
@@ -136,7 +127,8 @@ class BucketStorage {
136127 // Not flushing here - the flush will happen in the next step
137128 }, flush: false );
138129
139- final valid = await updateObjectsFromBuckets (forPriority: forPriority);
130+ final valid = await updateObjectsFromBuckets (checkpoint,
131+ forPartialPriority: forPriority);
140132 if (! valid) {
141133 return SyncLocalDatabaseResult (ready: false );
142134 }
@@ -146,11 +138,25 @@ class BucketStorage {
146138 return SyncLocalDatabaseResult (ready: true );
147139 }
148140
149- Future <bool > updateObjectsFromBuckets ({int ? forPriority}) async {
141+ Future <bool > updateObjectsFromBuckets (Checkpoint checkpoint,
142+ {int ? forPartialPriority}) async {
150143 return writeTransaction ((tx) async {
151- await tx.execute (
152- "INSERT INTO powersync_operations(op, data) VALUES(?, ?)" ,
153- ['sync_local' , forPriority]);
144+ await tx
145+ .execute ("INSERT INTO powersync_operations(op, data) VALUES(?, ?)" , [
146+ 'sync_local' ,
147+ forPartialPriority != null
148+ ? jsonEncode ({
149+ 'priority' : forPartialPriority,
150+ // If we're at a partial checkpoint, we should only publish the
151+ // buckets at the completed priority levels.
152+ 'buckets' : [
153+ for (final desc in checkpoint.checksums)
154+ // Note that higher priorities are encoded as smaller values
155+ if (desc.priority <= forPartialPriority) desc.bucket,
156+ ],
157+ })
158+ : null ,
159+ ]);
154160 final rs = await tx.execute ('SELECT last_insert_rowid() as result' );
155161 final result = rs[0 ]['result' ];
156162 if (result == 1 ) {
@@ -338,11 +344,9 @@ class BucketStorage {
338344
339345class BucketState {
340346 final String bucket;
341- final int priority;
342347 final String opId;
343348
344- const BucketState (
345- {required this .bucket, required this .priority, required this .opId});
349+ const BucketState ({required this .bucket, required this .opId});
346350
347351 @override
348352 String toString () {
@@ -351,23 +355,19 @@ class BucketState {
351355
352356 @override
353357 int get hashCode {
354- return Object .hash (bucket, priority, opId);
358+ return Object .hash (bucket, opId);
355359 }
356360
357361 @override
358362 bool operator == (Object other) {
359- return other is BucketState &&
360- other.priority == priority &&
361- other.bucket == bucket &&
362- other.opId == opId;
363+ return other is BucketState && other.bucket == bucket && other.opId == opId;
363364 }
364365}
365366
366367final class SyncDataBatch {
367368 final List <SyncBucketData > buckets;
368- final Map <String , BucketDescription > descriptions;
369369
370- SyncDataBatch (this .buckets, this .descriptions );
370+ SyncDataBatch (this .buckets);
371371}
372372
373373class SyncLocalDatabaseResult {
0 commit comments