This commit is contained in:
seb
2026-10-08 19:53:14 +02:00
parent c0a743654f
commit 0493b218d7

View File

@@ -359,12 +359,24 @@ export async function executeCompanyImport({
const brandEntries = Array.from(brandMap.entries()); const brandEntries = Array.from(brandMap.entries());
log.info(`Processing ${brandEntries.length} brands (Hersteller)...`); 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++) { for (let i = 0; i < brandEntries.length; i++) {
const [brandName, picSet] = brandEntries[i]; const [brandName, picSet] = brandEntries[i];
const lowerName = brandName.trim().toLowerCase();
const isNew = !existingBrandNames.has(lowerName);
try { try {
const brand = await store.brand.upsert(googleAuthId, { name: brandName }); const brand = await store.brand.upsert(googleAuthId, { name: brandName });
brandNameToId.set(brandName.toLowerCase(), brand.id); brandNameToId.set(lowerName, brand.id);
createdBrandCount++; if (isNew) {
createdBrandCount++;
existingBrandNames.add(lowerName);
}
// If brand doesn't have an image yet, import from manufacturerPictureFiles // If brand doesn't have an image yet, import from manufacturerPictureFiles
if ((!brand.pics || brand.pics.length === 0) && picSet.size > 0) { if ((!brand.pics || brand.pics.length === 0) && picSet.size > 0) {