Improve log

This commit is contained in:
Pierre-Henri
2024-04-24 14:34:33 +02:00
parent 66b3d5c5f2
commit b9cc9c9775
+4 -1
View File
@@ -180,7 +180,7 @@ export class HashIndexManager {
if (this.cache.size !== 0) { if (this.cache.size !== 0) {
cacheRows = this.loadIndexFromCache(); cacheRows = this.loadIndexFromCache();
} }
let didWrite=false;
for (const hash of this.targetHash) { for (const hash of this.targetHash) {
let existingRows: IndexLine[] = await this.loadIndex(hash); let existingRows: IndexLine[] = await this.loadIndex(hash);
let existingRowsAsMap: Map<string, IndexLine> = new Map(existingRows.map(row => [row.path, row])); let existingRowsAsMap: Map<string, IndexLine> = new Map(existingRows.map(row => [row.path, row]));
@@ -206,10 +206,12 @@ export class HashIndexManager {
// Append new cacheRows to the file // Append new cacheRows to the file
await fs.appendFile(this.filePaths[hash], csvString); await fs.appendFile(this.filePaths[hash], csvString);
didWrite = true;
} }
} }
} }
if(didWrite) {
const totalTime = performance.now() - start; const totalTime = performance.now() - start;
console.log(`Index saved in ${totalTime}ms`); 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 // Check if the time to save the index is greater than the interval time. increase the interval time if needed
@@ -217,6 +219,7 @@ export class HashIndexManager {
this.startAutoSave(totalTime * 10); this.startAutoSave(totalTime * 10);
console.log(`Index save interval increased to ${totalTime * 10}ms`); console.log(`Index save interval increased to ${totalTime * 10}ms`);
} }
}
this.indexOpsInProgress = false; this.indexOpsInProgress = false;
} }