Skip to content

fix: deduplicate OG images by URL to prevent unique constraint violation#743

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

fix: deduplicate OG images by URL to prevent unique constraint violation#743
Manishcs076 wants to merge 1 commit intoMerit-Systems:mainfrom
Manishcs076:fix/ogimage-unique-constraint

Conversation

@Manishcs076
Copy link
Copy Markdown

Summary

Fixes #287 — resource registration fails when scraped pages return duplicate OG image URLs.

Problem

When a page returns multiple OG image entries with the same URL, the concurrent Promise.all upserts race against each other on the (originId, url) composite unique constraint, causing a unique constraint violation.

Fix

Deduplicate OG images by URL using a Map before passing them to Promise.all. This ensures each URL is upserted exactly once per origin, eliminating the race condition.

Changes

  • apps/scan/src/services/db/resources/origin.ts: +5 lines — deduplicate ogImages array by URL before upserting

Minimal, surgical fix — no other behavior changed.

Prevents unique constraint violation when scraped pages return
duplicate OG image entries with the same URL. Uses a Map to
keep only the last occurrence of each URL before the parallel
upsert, matching the composite unique key (originId, url).

Fixes Merit-Systems#287
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 27, 2026

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

A member of the Team first needs to authorize it.

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

1 participant