Skip to content

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

Open
writsop wants to merge 1 commit intoMerit-Systems:mainfrom
writsop:fix/og-image-unique-constraint
Open

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

Conversation

@writsop
Copy link
Copy Markdown

@writsop writsop commented Apr 11, 2026

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

2 participants