fix(recipe): apply remote edits to recipes already synced locally - #533
Open
plusmobileapps wants to merge 1 commit into
Open
fix(recipe): apply remote edits to recipes already synced locally#533plusmobileapps wants to merge 1 commit into
plusmobileapps wants to merge 1 commit into
Conversation
The pull half of RecipeRepositoryImpl.syncWithRemote skipped every recipe it already had a local row for (`if (existing != null) continue`), so it only ever created rows. An edit made on another device reached Supabase but never came back down — the local copy only changed when that same device edited it. The push side was already correct: `update` sets isDirty = 1, updateRecipe pushes immediately, and a failed push is retried from getDirty() on the next sync. Reconcile remote edits into the existing row instead, following the pattern GroceryRepositoryImpl already uses. The new updateFromRemote query touches content columns plus isPublic/ownerId/updatedAt and deliberately leaves isDirty, remoteId and clientId alone. Rows with unpushed local changes are skipped — their dirty push runs earlier in the same pass, and overwriting here would drop an edit made while we were fetching — as are tombstoned rows, which keep their tombstone until the remote delete lands. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
The pull half of
RecipeRepositoryImpl.syncWithRemoteskipped every recipe it already had a local row for:So the pull only ever created rows. A recipe edited on one device reached Supabase but never came back down to any other device that already had it — the local copy only changed when that same device edited it.
The pull now reconciles remote edits into the existing row via a new
updateFromRemotequery.Why the push side is not the problem
Traced it:
Recipe.sq'supdatesetsisDirty = 1,updateRecipecallspushUpdateToRemoteimmediately, and a push that fails is retried fromgetDirty()on the next full sync. The data was reaching the remote fine.Notes for review
GroceryRepositoryImpl.syncWithRemotealready uses (queries.updateFromRemoteguarded by!existing.isDirty).updateFromRemoteupdates the content columns plusisPublic,ownerIdandupdatedAt, and deliberately does not touchisDirty,remoteIdorclientId.syncWithRemote_pull_does_not_resurrect_tombstoned_recipetest).Testing
Two new tests in
RecipeRepositoryImplTest:syncWithRemote_pull_applies_remote_edits_to_an_already_synced_recipe— verified it fails against the old code and passes with the fix.syncWithRemote_pull_does_not_clobber_a_recipe_with_unpushed_local_edits— makes the fake remote's upsert throw so the row is still dirty when the pull runs../gradlew :client:recipe:data:impl:jvmTest→ 27/27 passing.Known related gaps, not in this PR
RecipeBookRepositoryImplandMealPlanRepositoryImplhave the identicalif (existing != null) continuein their pulls, so e.g. a book renamed on one device never renames on another.fetchAccessibleRecipesalso covers shared-book recipes, so a naive prune would delete local copies whenever a book share is revoked — that needs its own thinking about ownership.🤖 Generated with Claude Code