fix(scan): prevent OgImage unique constraint conflict on registration (#287)#718
Open
pannous wants to merge 1 commit intoMerit-Systems:mainfrom
Open
fix(scan): prevent OgImage unique constraint conflict on registration (#287)#718pannous wants to merge 1 commit intoMerit-Systems:mainfrom
pannous wants to merge 1 commit intoMerit-Systems:mainfrom
Conversation
…istration (Merit-Systems#287) Deduplicate OG images by URL before upserting to prevent race conditions when multiple og:image tags resolve to the same URL. Process sequentially instead of concurrently to avoid composite unique constraint violations.
Contributor
|
@pannous is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition during origin registration where concurrent ogImage.upsert calls for duplicate OG image URLs could violate the (originId, url) unique constraint.
Changes:
- Deduplicate
origin.ogImagesby URL before persistence. - Replace concurrent
Promise.allupserts with a serializedfor...ofloop to eliminate intra-transaction races.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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.
Summary
Fixes #287 — OgImage unique constraint conflict when registering resources that share OG image URLs.
Root cause: When
origin.ogImagescontains duplicate URLs (e.g. from redirects or shared CDN),Promise.allfires concurrentupsertcalls with the same(originId, url)composite key. Both checkwheresimultaneously, find no match, and both attemptcreate— one fails with a unique constraint violation.Fix:
Map)for...ofinstead ofPromise.allto eliminate the race window on the@@unique([originId, url])constraintNote: The global
@uniqueonOgImage.urlwas already removed in migration20260115100000_remove_ogimage_url_unique_constraint, so different origins can share the same OG image URL. This fix addresses the remaining race condition within a single origin's ogImages array.Test plan
https://subdomain.example.comthat has OG imagehttps://cdn.example.com/og.pnghttps://example.comthat shares the same OG image URL