diff --git a/apps/scan/src/services/db/resources/origin.ts b/apps/scan/src/services/db/resources/origin.ts index 72e5a671e..a72b7f65a 100644 --- a/apps/scan/src/services/db/resources/origin.ts +++ b/apps/scan/src/services/db/resources/origin.ts @@ -45,32 +45,34 @@ export const upsertOrigin = async ( const originId = upsertedOrigin.id; - await Promise.all( - origin.ogImages.map(({ url, height, width, title, description }) => - tx.ogImage.upsert({ - where: { - originId_url: { - originId, - url, - }, - }, - update: { - height, - width, - title, - description, - }, - create: { + const uniqueOgImages = new Map( + origin.ogImages.map(img => [img.url, img]) + ); + + for (const { url, height, width, title, description } of uniqueOgImages.values()) { + await tx.ogImage.upsert({ + where: { + originId_url: { originId, url, - height, - width, - title, - description, }, - }) - ) - ); + }, + update: { + height, + width, + title, + description, + }, + create: { + originId, + url, + height, + width, + title, + description, + }, + }); + } return tx.resourceOrigin.findUnique({ where: { id: originId },