Skip to content

Commit 2be5919

Browse files
committed
Send partial checkpoint in sync test
1 parent 86623f4 commit 2be5919

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

packages/powersync_core/lib/src/sync/protocol.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ final class Checkpoint extends StreamingSyncLine {
136136
'write_checkpoint': writeCheckpoint,
137137
'buckets': checksums
138138
.where((c) => priority == null || c.priority <= priority)
139-
.map((c) => {
140-
'bucket': c.bucket,
141-
'checksum': c.checksum,
142-
'priority': c.priority,
143-
'count': c.count,
144-
})
139+
.map((c) => c.toJson())
145140
.toList(growable: false)
146141
};
147142
}
@@ -172,6 +167,15 @@ class BucketChecksum {
172167
checksum = json['checksum'] as int,
173168
count = json['count'] as int?,
174169
lastOpId = json['last_op_id'] as String?;
170+
171+
Map<String, Object?> toJson() {
172+
return {
173+
'bucket': bucket,
174+
'checksum': checksum,
175+
'priority': priority,
176+
'count': count,
177+
};
178+
}
175179
}
176180

177181
/// A variant of [Checkpoint] that may be sent when the server has already sent

packages/powersync_core/lib/src/sync/streaming_sync.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ class StreamingSyncImplementation implements StreamingSync {
367367
throw PowerSyncProtocolException(
368368
'Checkpoint diff without previous checkpoint');
369369
}
370-
_state.updateStatus((s) => s.downloading = true);
371370
final diff = line;
372371
final Map<String, BucketChecksum> newBuckets = {};
373372
for (var checksum in targetCheckpoint.checksums) {
@@ -385,6 +384,9 @@ class StreamingSyncImplementation implements StreamingSync {
385384
checksums: [...newBuckets.values],
386385
writeCheckpoint: diff.writeCheckpoint);
387386
targetCheckpoint = newCheckpoint;
387+
final initialProgress = await adapter.getBucketOperationProgress();
388+
_state.updateStatus(
389+
(s) => s.applyCheckpointStarted(initialProgress, newCheckpoint));
388390

389391
bucketMap = newBuckets.map((name, checksum) =>
390392
MapEntry(name, (name: name, priority: checksum.priority)));

packages/powersync_core/lib/src/sync/sync_status.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ typedef ProgressWithOperations = ({
335335
double fraction,
336336
});
337337

338-
/// Provides realtime progress about how PowerSync is downloading rows.
338+
/// Provides realtime progress on how PowerSync is downloading rows.
339339
///
340340
/// The reported progress always reflects the status towards the end of a
341341
/// sync iteration (after which a consistent snapshot of all buckets is

packages/powersync_core/test/in_memory_sync_test.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ void main() {
418418

419419
// Emit new data, progress should be 0/2 instead of 10/12
420420
syncService.addLine({
421-
'checkpoint': Checkpoint(
422-
lastOpId: '12',
423-
checksums: [bucket('a', 12)],
424-
)
421+
'checkpoint_diff': {
422+
'last_op_id': '12',
423+
'updated_buckets': [bucket('a', 12)],
424+
'removed_buckets': const <Object?>[],
425+
},
425426
});
426427
await expectProgress(status, total: progress(0, 2));
427428
addDataLine('a', 2);

0 commit comments

Comments
 (0)