refactor: Comment out console logs for improved performance and clarity during sync operations
This commit is contained in:
@@ -7,7 +7,7 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
|
||||
if (changed) {
|
||||
console.log('🎉 Event received: Category tree updated! Root nodes:', tree.length);
|
||||
} 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
|
||||
@@ -28,7 +28,7 @@ categorySyncer.on('synced', async ({ tree, unprunedTree, changed }) => {
|
||||
};
|
||||
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 categoryProductsSyncer.syncProducts(categoryIds);
|
||||
|
||||
@@ -11,7 +11,7 @@ class CategoryProductsSyncer extends EventEmitter {
|
||||
return CategoryProductsSyncer.instance;
|
||||
}
|
||||
this.cacheBaseDir = process.env.CACHE_LOCATION || '.';
|
||||
|
||||
|
||||
// Track syncing state
|
||||
this.isSyncing = false;
|
||||
this.queuedCategoryIds = null;
|
||||
@@ -79,14 +79,14 @@ class CategoryProductsSyncer extends EventEmitter {
|
||||
// 2. Update/Create product lists for all valid categories
|
||||
// We update all because product assignments might have changed even if category exists
|
||||
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);
|
||||
} else {
|
||||
console.log(`✅ No categories to sync products for.`);
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -116,7 +116,7 @@ class CategoryProductsSyncer extends EventEmitter {
|
||||
AND ab.kPlattform = ${process.env.JTL_PLATTFORM_ID}
|
||||
AND ab.kShop = ${process.env.JTL_SHOP_ID}
|
||||
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
|
||||
@@ -146,7 +146,7 @@ class CategoryProductsSyncer extends EventEmitter {
|
||||
|
||||
// Group results by kKategorie
|
||||
const productsByCategory = {};
|
||||
|
||||
|
||||
// Initialize arrays for all requested IDs (so we create empty files for empty categories)
|
||||
chunk.forEach(id => {
|
||||
productsByCategory[id] = [];
|
||||
@@ -187,15 +187,15 @@ class CategoryProductsSyncer extends EventEmitter {
|
||||
|
||||
const processed = Math.min(i + chunkSize, 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 {
|
||||
console.log(`⏳ Processed products for ${processed}/${ids.length} categories...`);
|
||||
//console.log(`⏳ Processed products for ${processed}/${ids.length} categories...`);
|
||||
}
|
||||
}
|
||||
|
||||
// Sync all collected images at once
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class CategorySyncer extends EventEmitter {
|
||||
async _doSync() {
|
||||
this.isSyncing = true;
|
||||
const startTime = Date.now();
|
||||
console.log('🚀 Starting sync...');
|
||||
//console.log('🚀 Starting sync...');
|
||||
|
||||
try {
|
||||
await this._syncFromDb();
|
||||
@@ -65,7 +65,7 @@ class CategorySyncer extends EventEmitter {
|
||||
// Log completion and next sync time
|
||||
const syncInterval = parseInt(process.env.SYNC_INTERVAL_MS) || 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) {
|
||||
console.error('❌ Sync failed:', err);
|
||||
} finally {
|
||||
@@ -159,7 +159,7 @@ class CategorySyncer extends EventEmitter {
|
||||
this.lastTreeString = treeString;
|
||||
console.log('📢 Tree updated.');
|
||||
} else {
|
||||
console.log('🤷 No changes detected in category tree.');
|
||||
//console.log('🤷 No changes detected in category tree.');
|
||||
}
|
||||
|
||||
this.emit('synced', { tree, unprunedTree, changed });
|
||||
|
||||
@@ -88,7 +88,7 @@ class PictureSyncer {
|
||||
console.log(`📥 Downloading ${toDownload.length} new images for group '${groupName}'...`);
|
||||
await this._downloadImages(toDownload, groupDir);
|
||||
} else {
|
||||
console.log(`✅ No new images to download for group '${groupName}'.`);
|
||||
//console.log(`✅ No new images to download for group '${groupName}'.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user