From 0493b218d79f778947592169d9359bc08ea3dc22 Mon Sep 17 00:00:00 2001 From: seb Date: Thu, 8 Oct 2026 19:53:14 +0200 Subject: [PATCH] u --- src/services/companyImport.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/companyImport.js b/src/services/companyImport.js index 47c767d..3c6dd85 100644 --- a/src/services/companyImport.js +++ b/src/services/companyImport.js @@ -359,12 +359,24 @@ export async function executeCompanyImport({ const brandEntries = Array.from(brandMap.entries()); log.info(`Processing ${brandEntries.length} brands (Hersteller)...`); + // Fetch existing brands to accurately track new vs existing + const existingBrands = await store.brand.list(googleAuthId); + const existingBrandNames = new Set( + existingBrands.map((b) => (b.name || '').trim().toLowerCase()).filter(Boolean) + ); + for (let i = 0; i < brandEntries.length; i++) { const [brandName, picSet] = brandEntries[i]; + const lowerName = brandName.trim().toLowerCase(); + const isNew = !existingBrandNames.has(lowerName); + try { const brand = await store.brand.upsert(googleAuthId, { name: brandName }); - brandNameToId.set(brandName.toLowerCase(), brand.id); - createdBrandCount++; + brandNameToId.set(lowerName, brand.id); + if (isNew) { + createdBrandCount++; + existingBrandNames.add(lowerName); + } // If brand doesn't have an image yet, import from manufacturerPictureFiles if ((!brand.pics || brand.pics.length === 0) && picSet.size > 0) {