diff --git a/src/controllers/importController.js b/src/controllers/importController.js index 4c05cb7..427085b 100644 --- a/src/controllers/importController.js +++ b/src/controllers/importController.js @@ -92,6 +92,7 @@ async function importCardsInternal() { const cardValues = [], cardParams = []; const imageValues = [], imageParams = []; const csrValues = [], csrParams = []; + const batchImageIds = new Set(); for (const card of batch) { const fp = cardFingerprint(card); @@ -107,7 +108,8 @@ async function importCardsInternal() { if (Array.isArray(card.card_images)) { for (const img of card.card_images) { - if (!existingImageIds.has(img.id)) { + if (!existingImageIds.has(img.id) && !batchImageIds.has(img.id)) { + batchImageIds.add(img.id); imageValues.push('(?, ?, ?)'); imageParams.push(img.id, card.id, img.image_url); addedImages++; @@ -151,6 +153,7 @@ async function importCardsInternal() { if (imageValues.length) { await conn.execute(` INSERT INTO card_images (image_id, card_id, image_url) VALUES ${imageValues.join(', ')} + ON DUPLICATE KEY UPDATE image_url = VALUES(image_url) `, imageParams); }