refactor: Comment out console logs for improved performance and clarity during sync operations

This commit is contained in:
sebseb7
2025-11-23 13:28:35 +01:00
parent 22a4b88f58
commit 320bcd4641
4 changed files with 14 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
if (changed) { if (changed) {
console.log('🎉 Event received: Category tree updated! Root nodes:', tree.length); console.log('🎉 Event received: Category tree updated! Root nodes:', tree.length);
} else { } else {
console.log('🎉 Event received: Sync finished (no changes). Checking images and products...'); //console.log('🎉 Event received: Sync finished (no changes). Checking images and products...');
} }
// Extract all kBild IDs and kKategorie IDs from unpruned tree // Extract all kBild IDs and kKategorie IDs from unpruned tree
@@ -28,7 +28,7 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
}; };
traverse(unprunedTree); traverse(unprunedTree);
console.log(`🔍 Found ${imageIds.length} images and ${categoryIds.length} categories.`); //console.log(`🔍 Found ${imageIds.length} images and ${categoryIds.length} categories.`);
await pictureSyncer.syncImages(imageIds, 'categories'); await pictureSyncer.syncImages(imageIds, 'categories');
await categoryProductsSyncer.syncProducts(categoryIds); await categoryProductsSyncer.syncProducts(categoryIds);

View File

@@ -79,14 +79,14 @@ class CategoryProductsSyncer extends EventEmitter {
// 2. Update/Create product lists for all valid categories // 2. Update/Create product lists for all valid categories
// We update all because product assignments might have changed even if category exists // We update all because product assignments might have changed even if category exists
if (validIds.size > 0) { if (validIds.size > 0) {
console.log(`📦 Syncing products for ${validIds.size} categories...`); //console.log(`📦 Syncing products for ${validIds.size} categories...`);
await this._fetchAndWriteProducts([...validIds], productsDir); await this._fetchAndWriteProducts([...validIds], productsDir);
} else { } else {
console.log(`✅ No categories to sync products for.`); console.log(`✅ No categories to sync products for.`);
} }
const duration = Date.now() - startTime; const duration = Date.now() - startTime;
console.log(`✅ Product sync completed in ${duration}ms.`); //console.log(`✅ Product sync completed in ${duration}ms.`);
} }
async _fetchAndWriteProducts(ids, dir) { async _fetchAndWriteProducts(ids, dir) {
@@ -116,7 +116,7 @@ class CategoryProductsSyncer extends EventEmitter {
AND ab.kPlattform = ${process.env.JTL_PLATTFORM_ID} AND ab.kPlattform = ${process.env.JTL_PLATTFORM_ID}
AND ab.kShop = ${process.env.JTL_SHOP_ID} AND ab.kShop = ${process.env.JTL_SHOP_ID}
AND ka.kKategorie IN (${list}) AND ka.kKategorie IN (${list})
ORDER BY a.bRowversion DESC, ab.bRowversion DESC ORDER BY (CASE WHEN a.bRowversion > ab.bRowversion THEN a.bRowversion ELSE ab.bRowversion END) DESC
`); `);
// Collect all kArtikel IDs to fetch images // Collect all kArtikel IDs to fetch images
@@ -187,15 +187,15 @@ class CategoryProductsSyncer extends EventEmitter {
const processed = Math.min(i + chunkSize, ids.length); const processed = Math.min(i + chunkSize, ids.length);
if (processed === ids.length) { if (processed === ids.length) {
console.log(`✅ Processed products for ${processed}/${ids.length} categories.`); //console.log(`✅ Processed products for ${processed}/${ids.length} categories.`);
} else { } else {
console.log(`⏳ Processed products for ${processed}/${ids.length} categories...`); //console.log(`⏳ Processed products for ${processed}/${ids.length} categories...`);
} }
} }
// Sync all collected images at once // Sync all collected images at once
if (globalImageIds.size > 0) { if (globalImageIds.size > 0) {
console.log(`🖼️ Syncing ${globalImageIds.size} product images...`); //console.log(`🖼️ Syncing ${globalImageIds.size} product images...`);
await pictureSyncer.syncImages(Array.from(globalImageIds), 'products'); await pictureSyncer.syncImages(Array.from(globalImageIds), 'products');
} }

View File

@@ -56,7 +56,7 @@ class CategorySyncer extends EventEmitter {
async _doSync() { async _doSync() {
this.isSyncing = true; this.isSyncing = true;
const startTime = Date.now(); const startTime = Date.now();
console.log('🚀 Starting sync...'); //console.log('🚀 Starting sync...');
try { try {
await this._syncFromDb(); await this._syncFromDb();
@@ -65,7 +65,7 @@ class CategorySyncer extends EventEmitter {
// Log completion and next sync time // Log completion and next sync time
const syncInterval = parseInt(process.env.SYNC_INTERVAL_MS) || 60000; const syncInterval = parseInt(process.env.SYNC_INTERVAL_MS) || 60000;
const minutes = Math.round(syncInterval / 60000); const minutes = Math.round(syncInterval / 60000);
console.log(`✅ Sync completed in ${duration}ms. Next sync in ${minutes} minute${minutes !== 1 ? 's' : ''}`); //console.log(`✅ Sync completed in ${duration}ms. Next sync in ${minutes} minute${minutes !== 1 ? 's' : ''}`);
} catch (err) { } catch (err) {
console.error('❌ Sync failed:', err); console.error('❌ Sync failed:', err);
} finally { } finally {
@@ -159,7 +159,7 @@ class CategorySyncer extends EventEmitter {
this.lastTreeString = treeString; this.lastTreeString = treeString;
console.log('📢 Tree updated.'); console.log('📢 Tree updated.');
} else { } else {
console.log('🤷 No changes detected in category tree.'); //console.log('🤷 No changes detected in category tree.');
} }
this.emit('synced', { tree, unprunedTree, changed }); this.emit('synced', { tree, unprunedTree, changed });

View File

@@ -88,7 +88,7 @@ class PictureSyncer {
console.log(`📥 Downloading ${toDownload.length} new images for group '${groupName}'...`); console.log(`📥 Downloading ${toDownload.length} new images for group '${groupName}'...`);
await this._downloadImages(toDownload, groupDir); await this._downloadImages(toDownload, groupDir);
} else { } else {
console.log(`✅ No new images to download for group '${groupName}'.`); //console.log(`✅ No new images to download for group '${groupName}'.`);
} }
} }