Library scan: leave one core free at startup

The startup channel scan used available_parallelism() (every core), which
could briefly peg the whole box on a cold/large library. Cap it at cores-1
so the machine stays responsive; the scan is disk-I/O-bound and runs as a
background task, so one fewer thread costs little. Mirrors the headroom the
fingerprint pass and thumbnail pool already leave.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Luna 2026-06-15 18:58:56 -07:00
parent 5ffdb179f7
commit 015d03751c

View file

@ -224,10 +224,11 @@ pub fn scan_channels_with_cache(youtube_root: &Path, cache: Option<&Database>) -
} }
} }
let n_workers = std::thread::available_parallelism() // Leave one core free so a cold/large scan doesn't peg every core and
.map(|n| n.get()) // make the box unresponsive — this runs as a background task and the scan
.unwrap_or(4) // is mostly disk-I/O-bound anyway, so giving up one thread costs little.
.min(dirs.len().max(1)); let cores = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(4);
let n_workers = cores.saturating_sub(1).max(1).min(dirs.len().max(1));
// Hand each worker its own Database handle via .clone() (Arc inside, // Hand each worker its own Database handle via .clone() (Arc inside,
// cheap). Workers without a cache get None. // cheap). Workers without a cache get None.
let cache_handle: Option<Database> = cache.cloned(); let cache_handle: Option<Database> = cache.cloned();