Skip to content

Commit 937ed50

Browse files
committed
Set count_at_last in SDK
1 parent 74387b8 commit 937ed50

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

crates/core/src/sync_local.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ GROUP BY b.row_type, b.row_id",
259259
fn set_last_applied_op(&self) -> Result<(), SQLiteError> {
260260
match &self.partial {
261261
Some(partial) => {
262-
// Note: This one deliberately doesn't reset count_since_last or updates
263-
// count_at_last! We want a download progress to always cover a complete sync
264-
// checkpoint instead of resetting for partial completions.
265262
// language=SQLite
266263
let updated = self
267264
.db
@@ -280,10 +277,8 @@ GROUP BY b.row_type, b.row_id",
280277
self.db
281278
.exec_safe(
282279
"UPDATE ps_buckets
283-
SET last_applied_op = last_op,
284-
count_since_last = 0,
285-
count_at_last = count_at_last + count_since_last
286-
WHERE (last_applied_op != last_op) OR count_since_last",
280+
SET last_applied_op = last_op
281+
WHERE last_applied_op != last_op",
287282
)
288283
.into_db_result(self.db)?;
289284
}

dart/test/sync_test.dart

+16-11
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,11 @@ void main() {
278278
isTrue,
279279
);
280280

281-
// Despite committing data, a partial checkpoint should not clear download
282-
// progress stats.
281+
// Running partial or complete checkpoints should not reset stats, client
282+
// SDKs are responsible for that.
283283
expectProgress(0, 2);
284284
expect(db.select('SELECT * FROM items'), isNotEmpty);
285285

286-
// Full checkpoint sets count_at_last
287286
expect(
288287
pushCheckpointComplete(
289288
'2',
@@ -292,19 +291,25 @@ void main() {
292291
),
293292
isTrue,
294293
);
294+
expectProgress(0, 2);
295+
296+
db.execute('''
297+
UPDATE ps_buckets SET count_since_last = 0, count_at_last = ?1->name
298+
WHERE ?1->name IS NOT NULL
299+
''', [
300+
json.encode({bucket: 2}),
301+
]);
295302
expectProgress(2, 0);
296303

297304
// Run another iteration of this
298305
pushSyncData(bucket, '3', 'row-3', 'PUT', {'col': 'hi'});
299306
expectProgress(2, 1);
300-
expect(
301-
pushCheckpointComplete(
302-
'3',
303-
null,
304-
[_bucketChecksum(bucket, 1, checksum: 0)],
305-
),
306-
isTrue,
307-
);
307+
db.execute('''
308+
UPDATE ps_buckets SET count_since_last = 0, count_at_last = ?1->name
309+
WHERE ?1->name IS NOT NULL
310+
''', [
311+
json.encode({bucket: 3}),
312+
]);
308313
expectProgress(3, 0);
309314
});
310315
});

0 commit comments

Comments
 (0)