@@ -75,7 +75,7 @@ FROM json_each(?) e",
7575 // operations when last_applied_op = 0.
7676 // We do still need to do the "supersede_statement" step for this case, since a REMOVE
7777 // operation can supersede another PUT operation we're syncing at the same time.
78- let mut last_applied_op = bucket_statement. column_int64 ( 1 ) ?;
78+ let mut is_empty = bucket_statement. column_int64 ( 1 ) ? == 0 ;
7979
8080 // Statement to supersede (replace) operations with the same key.
8181 // language=SQLite
@@ -134,11 +134,12 @@ INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES(?1, ?2)",
134134 add_checksum = add_checksum. wrapping_add ( supersede_checksum) ;
135135 op_checksum = op_checksum. wrapping_sub ( supersede_checksum) ;
136136
137- if superseded_op <= last_applied_op {
138- // Superseded an operation previously applied - we cannot skip removes
139- // For initial sync, last_applied_op = 0, so this is always false.
140- // For subsequent sync, this is only true if the row was previously
141- // synced, not when it was first synced in the current batch.
137+ // Superseded an operation, only skip if the bucket was empty
138+ // Previously this checked "superseded_op <= last_applied_op".
139+ // However, that would not account for a case where a previous
140+ // PUT operation superseded the original PUT operation in this
141+ // same batch, in which case superseded_op is not accurate for this.
142+ if !is_empty {
142143 superseded = true ;
143144 }
144145 }
@@ -225,7 +226,7 @@ WHERE bucket = ?1",
225226 clear_statement2. exec ( ) ?;
226227
227228 add_checksum = 0 ;
228- last_applied_op = 0 ;
229+ is_empty = true ;
229230 op_checksum = 0 ;
230231 }
231232 }
0 commit comments