From 241aceb06608ad01fa420a6461544867a53e41da Mon Sep 17 00:00:00 2001 From: 4 Bytes Robby Date: Tue, 23 Jun 2026 08:23:51 +0200 Subject: [PATCH] fix: only show filename in ingest progress after 3s delay --- src/ingest/index.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ingest/index.ts b/src/ingest/index.ts index eb3f913..a9b522f 100644 --- a/src/ingest/index.ts +++ b/src/ingest/index.ts @@ -75,6 +75,9 @@ const FILE_TIMEOUT_MS = 30_000; // 30 seconds per file /** Files exceeding this duration get logged to app.log as a warning. */ const SLOW_FILE_WARN_MS = 10_000; // 10 seconds +/** Delay before showing current file name in progress (3 seconds). */ +const SLOW_FILE_DISPLAY_MS = 3_000; + // --------------------------------------------------------------------------- // Progress event helpers (gated on BRAIN_DEBUG=true) // --------------------------------------------------------------------------- @@ -203,13 +206,11 @@ export async function ingestPath( return; } - // Report which file is being processed - options?.progressCallback?.({ - current: i + 1, - total: walkedFiles.length, - currentFile: filePath, - currentFileSize: fileStats.size, - }); + // Only show filename in progress if the file takes longer than 3s + let slowFileTimer: ReturnType | undefined; + slowFileTimer = setTimeout(() => { + options?.progressCallback?.({ current: i + 1, total: walkedFiles.length, currentFile: filePath, currentFileSize: fileStats.size }); + }, SLOW_FILE_DISPLAY_MS) as unknown as ReturnType; // Read file as raw buffer — binary-safe hashing (avoids encoding issues) let buf: ArrayBuffer; @@ -437,11 +438,8 @@ export async function ingestPath( result.filesIndexed++; result.filesProcessed++; - options?.progressCallback?.({ - current: result.filesProcessed, - total: walkedFiles.length, - currentFile: undefined, - }); + if (slowFileTimer) clearTimeout(slowFileTimer); + options?.progressCallback?.({ current: result.filesProcessed, total: walkedFiles.length }); // Per-file timing debug (BRAIN_DEBUG only) if (process.env.BRAIN_DEBUG === "true") {