Skip to content

fix: deduplicate OG images to prevent unique constraint race (#287)#717

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

fix: deduplicate OG images to prevent unique constraint race (#287)#717
pannous wants to merge 1 commit intoMerit-Systems:mainfrom
pannous:fix/ogimage-unique-constraint-287

Conversation

@pannous
Copy link
Copy Markdown

@pannous pannous commented Mar 14, 2026

Summary

Fixes #287 — OgImage unique constraint conflict during resource registration.

  • Root cause: When a scraped page contains duplicate og:image tags pointing to the same URL, Promise.all fires multiple upsert calls with the same compound key (originId, url) simultaneously, causing a race condition and unique constraint violation.
  • Fix: Deduplicate OG images by URL before upserting, ensuring each URL is processed exactly once per batch. Uses a Map keyed by URL so the last occurrence wins (preserving the most recent metadata).

Note: The original @unique constraint on url alone was already removed in PR #472, which resolved the cross-origin conflict. This PR addresses the remaining within-batch race condition.

Changes

  • apps/scan/src/services/db/resources/origin.ts: Added URL-based deduplication of OG images before the Promise.all upsert loop.

Test plan

  • Verified the fix is minimal (single file, 4 lines added)
  • Registration with duplicate OG image URLs in metadata should succeed
  • Registration with unique OG image URLs continues to work as before

…ondition (Merit-Systems#287)

When scraped pages contain duplicate og:image tags pointing to the same
URL, the parallel upsert calls within Promise.all race on the same
compound unique key (originId, url), causing a unique constraint violation.

Deduplicate OG images by URL before upserting so each URL is processed
exactly once per batch.
Copilot AI review requested due to automatic review settings March 14, 2026 18:52
@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

Fixes a race condition during origin registration when scraped Open Graph metadata contains duplicate og:image URLs, by deduplicating images prior to performing batched Prisma upsert operations.

Changes:

  • Deduplicate origin.ogImages by url before running the Promise.all upsert loop to avoid concurrent upserts of the same (originId, url) key.

💡 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.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402scan Ready Ready Preview, Comment Mar 24, 2026 1:42am

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