From ebe78b270c99ec4eea6775e8e25215002289f250 Mon Sep 17 00:00:00 2001 From: elipeter Date: Tue, 24 Jun 2025 22:44:57 +0200 Subject: [PATCH] fix: Limit diagnostics output on non indexed scan to a maximum number of results based on configuration --- src/commands/scan.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/commands/scan.rs b/src/commands/scan.rs index 9c2ff0bb..06571b48 100644 --- a/src/commands/scan.rs +++ b/src/commands/scan.rs @@ -103,7 +103,12 @@ fn scan_filesystem(root: &Path, cfg: &Config) -> NyxResult> { Ok::<(), DynError>(()) })?; - Ok(acc.into_inner()?) + let mut diags = acc.into_inner()?; + if let Some(max) = cfg.output.max_results { + diags.truncate(max as usize); + } + + Ok(diags) } pub fn scan_with_index_parallel( @@ -115,12 +120,10 @@ pub fn scan_with_index_parallel( let idx = Indexer::from_pool(project, &pool)?; idx.get_files(project)? }; - - // ① Collect per-path Vec without a global mutex + let diag_map: DashMap> = DashMap::new(); files.into_par_iter().for_each_init( - // ② A single Indexer per Rayon worker thread || Indexer::from_pool(project, &pool).expect("db pool"), |idx, path| { let needs_scan = idx.should_scan(&path).unwrap_or(true); @@ -153,8 +156,7 @@ pub fn scan_with_index_parallel( // Optional, heavy: only vacuum on --rebuild-index // if rebuild { idx.vacuum()?; } - - // flatten + let mut diags: Vec = diag_map.into_iter().flat_map(|(_, v)| v).collect(); if let Some(max) = cfg.output.max_results {