Fix duplicate image_id crash: deduplicate within batch, restore ON DUPLICATE KEY UPDATE
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user