fix(recipes): make URL import idempotent per-user (no duplicate saves) - #139
Merged
Conversation
Source-URL uniqueness was enforced only on the extraction cache (canonical_recipes.normalized_url), NOT on a user's collection — so saving the same recipe twice (e.g. an MCP agent calling save_recipe more than once) created duplicate recipe rows pointing at the same canonical. There was no per-user dedup anywhere: ImportFromURL -> createImportedRecipe -> CreateRecipe is a plain insert. - Add RecipeRepo.GetUserRecipeByCanonical(userID, canonicalID) (repo + mock). - In createImportedRecipe, when canonicalID != nil (URL imports), return the user's existing recipe for that canonical instead of inserting a duplicate. Vision/copypasta/video imports (nil canonical) and fork/regen/generate are unaffected — they legitimately create new rows. - Mock CreateRecipe now populates CreatedByID from the association (mirrors GORM) so lookups behave like the DB. - Dedup-lookup failure logs and proceeds (never blocks an import). A partial unique index on (created_by_id, canonical_id) is a sensible follow-up once existing dupes are cleaned. Test: import same canonical twice -> 1 row + same id returned; different canonical -> new row. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Problem
A user saving the same recipe twice (found while recording the ChatGPT demo — the agent called
save_recipetwice) got duplicate rows in their collection. Source-URL uniqueness is enforced only on the extraction cache (canonical_recipes.normalized_url), never on the user'srecipescollection — andImportFromURL → createImportedRecipe → CreateRecipeis a plain insert with no per-user existence check.Fix
RecipeRepo.GetUserRecipeByCanonical(userID, canonicalID)(repo + mock).createImportedRecipe: whencanonicalID != nil(URL imports), return the user's existing recipe for that canonical instead of inserting a dupe. Vision/copypasta/video imports (nil canonical) and fork/regen/generate are untouched.CreateRecipenow setsCreatedByIDfrom the association (mirrors GORM).Test
TestImportIdempotent_SameCanonicalNoDuplicate: same canonical twice → 1 row + same id; different canonical → new row. Full suite green (16 pkgs).Follow-up (optional): a partial unique index
(created_by_id, canonical_id) WHERE deleted_at IS NULL AND canonical_id IS NOT NULLonce the existing stray dupe is deleted.🤖 Generated with Claude Code