Merge pull request #2 from ecpeter23/bug/fix-max-results

fix: Limit diagnostics output on non indexed scan to a maximum number…
This commit is contained in:
Eli Peter 2025-06-24 22:51:30 +02:00 committed by GitHub
commit a0c9d0f9d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -103,7 +103,12 @@ fn scan_filesystem(root: &Path, cfg: &Config) -> NyxResult<Vec<Diag>> {
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<Diag> without a global mutex
let diag_map: DashMap<String, Vec<Diag>> = 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,14 +156,12 @@ pub fn scan_with_index_parallel(
// Optional, heavy: only vacuum on --rebuild-index
// if rebuild { idx.vacuum()?; }
// flatten
let mut diags: Vec<Diag> = diag_map.into_iter().flat_map(|(_, v)| v).collect();
if let Some(max) = cfg.output.max_results {
diags.truncate(max as usize);
}
// Flatten
Ok(diags)
}