Revert optimization breaking deletes #45
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If a client syncs the following two batches:
The REMOVE could be an actual delete, or the row just being removed from the bucket.
Then the row was correctly removed from the local
ps_oplog
table, but not from the data tables. The missing part was in adding the row tops_updated_rows
.This broken optimization was introduced in b8103bf / #19 / v0.2.0. The remainder of the optimizations in #19 are still valid, but this specific generalization is not. The idea for this optimization was that if a row was both created and removed in the same batch of data, we could ignore those operations completely. However, it did not account for rows that already existed before the sync batch, in which case we can't ignore the remove.
See test case: powersync-ja/powersync.dart#211
To recover from the issue, a client has to re-sync from scratch. Updating to the fixed version will only prevent new cases of the issue from happening, and won't fix existing cases.
Confirmed the fix here with both a unit test (powersync-ja/powersync.dart#211) and manual testing.