Skip to content

fix(scan): prevent OgImage unique constraint conflict on registration (#287)#718

Open
pannous wants to merge 1 commit intoMerit-Systems:mainfrom
pannous:fix/ogimage-unique-constraint-287-v2
Open

fix(scan): prevent OgImage unique constraint conflict on registration (#287)#718
pannous wants to merge 1 commit intoMerit-Systems:mainfrom
pannous:fix/ogimage-unique-constraint-287-v2

Conversation

@pannous
Copy link
Copy Markdown

@pannous pannous commented Mar 14, 2026

Summary

Fixes #287 — OgImage unique constraint conflict when registering resources that share OG image URLs.

Root cause: When origin.ogImages contains duplicate URLs (e.g. from redirects or shared CDN), Promise.all fires concurrent upsert calls with the same (originId, url) composite key. Both check where simultaneously, find no match, and both attempt create — one fails with a unique constraint violation.

Fix:

  • Deduplicate OG images by URL before processing (last occurrence wins via Map)
  • Serialize upserts with for...of instead of Promise.all to eliminate the race window on the @@unique([originId, url]) constraint

Note: The global @unique on OgImage.url was already removed in migration 20260115100000_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

  • Register Resource A with origin https://subdomain.example.com that has OG image https://cdn.example.com/og.png
  • Register Resource B with origin https://example.com that shares the same OG image URL
  • Verify both registrations succeed without constraint errors
  • Verify OG images with duplicate URLs in a single page's meta tags don't cause failures

…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.
Copilot AI review requested due to automatic review settings March 14, 2026 18:55
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 14, 2026

@pannous is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ogImages by URL before persistence.
  • Replace concurrent Promise.all upserts with a serialized for...of loop 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Unable to register resource due to OgImage unique constraint conflict

2 participants