@@ -75,7 +75,7 @@ FROM json_each(?) e",
75
75
// operations when last_applied_op = 0.
76
76
// We do still need to do the "supersede_statement" step for this case, since a REMOVE
77
77
// 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 ;
79
79
80
80
// Statement to supersede (replace) operations with the same key.
81
81
// language=SQLite
@@ -134,11 +134,12 @@ INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES(?1, ?2)",
134
134
add_checksum = add_checksum. wrapping_add ( supersede_checksum) ;
135
135
op_checksum = op_checksum. wrapping_sub ( supersede_checksum) ;
136
136
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 {
142
143
superseded = true ;
143
144
}
144
145
}
@@ -225,7 +226,7 @@ WHERE bucket = ?1",
225
226
clear_statement2. exec ( ) ?;
226
227
227
228
add_checksum = 0 ;
228
- last_applied_op = 0 ;
229
+ is_empty = true ;
229
230
op_checksum = 0 ;
230
231
}
231
232
}
0 commit comments