mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-09 19:45:13 +02:00
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:
commit
a0c9d0f9d4
1 changed files with 9 additions and 8 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue