From b9cc9c9775d5f048d847587d94777958df0e5497 Mon Sep 17 00:00:00 2001 From: Pierre-Henri Date: Wed, 24 Apr 2024 14:34:33 +0200 Subject: [PATCH] Improve log --- src/lib/hash-compute/HashIndexManager.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/lib/hash-compute/HashIndexManager.ts b/src/lib/hash-compute/HashIndexManager.ts index 136616b..6084b2f 100644 --- a/src/lib/hash-compute/HashIndexManager.ts +++ b/src/lib/hash-compute/HashIndexManager.ts @@ -180,7 +180,7 @@ export class HashIndexManager { if (this.cache.size !== 0) { cacheRows = this.loadIndexFromCache(); } - + let didWrite=false; for (const hash of this.targetHash) { let existingRows: IndexLine[] = await this.loadIndex(hash); let existingRowsAsMap: Map = new Map(existingRows.map(row => [row.path, row])); @@ -206,16 +206,19 @@ export class HashIndexManager { // Append new cacheRows to the file await fs.appendFile(this.filePaths[hash], csvString); + didWrite = true; } } } - const totalTime = performance.now() - start; - console.log(`Index saved in ${totalTime}ms`); - // Check if the time to save the index is greater than the interval time. increase the interval time if needed - if (totalTime * 10 > this.intervalTime) { - this.startAutoSave(totalTime * 10); - console.log(`Index save interval increased to ${totalTime * 10}ms`); + if(didWrite) { + const totalTime = performance.now() - start; + console.log(`Index saved in ${totalTime}ms`); + // Check if the time to save the index is greater than the interval time. increase the interval time if needed + if (totalTime * 10 > this.intervalTime) { + this.startAutoSave(totalTime * 10); + console.log(`Index save interval increased to ${totalTime * 10}ms`); + } } this.indexOpsInProgress = false; }