Skip to content

fix: deduplicate ogImages by URL before upsert to prevent unique constraint violation#774

Closed
writsop wants to merge 1 commit into
Merit-Systems:mainfrom
writsop:fix/og-image-unique-constraint
Closed

fix: deduplicate ogImages by URL before upsert to prevent unique constraint violation#774
writsop wants to merge 1 commit into
Merit-Systems:mainfrom
writsop:fix/og-image-unique-constraint

Conversation

@writsop

@writsop writsop commented Apr 11, 2026

Copy link
Copy Markdown

When multiple OG images share the same URL (e.g. from meta tags), the parallel Promise.all upsert calls race on the (originId, url) unique constraint, causing PrismaClientKnownRequestError P2002.

Fix

Deduplicate the ogImages array by URL using a Map before upserting, keeping the last occurrence (matching the current upsert "last write wins" semantics).

const uniqueOgImages = [...new Map(origin.ogImages.map(img => [img.url, img])).values()];

Fixes #287

…traint violation

When multiple OG images share the same URL, the parallel upsert calls
race on the (originId, url) unique constraint causing
PrismaClientKnownRequestError P2002.

Deduplicate the array by URL using a Map before upserting, keeping the
last occurrence (matching current upsert "last write wins" semantics).

Fixes Merit-Systems#287
@shafu0x

shafu0x commented May 20, 2026

Copy link
Copy Markdown
Contributor

Closing as part of external PR cleanup.

@shafu0x shafu0x closed this May 20, 2026
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

3 participants