From e767a0b6b922f71e3813e269b2c6a1412f15ccd4 Mon Sep 17 00:00:00 2001 From: jakka Date: Wed, 2 Jul 2025 19:33:32 +0300 Subject: made indexing single-threaded so db doesnt panic and no performance decrease --- src/files.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 8b089e8..c5583ee 100644 --- a/src/files.rs +++ b/src/files.rs @@ -90,17 +90,13 @@ pub fn index_files_recursively( .with_style(ProgressStyle::with_template(BAR_TEMPLATE)?.progress_chars("#>-")) .with_message("Indexing"); - let mut paths = Vec::new(); - - for entry in WalkDir::new(abspath) { + for entry in WalkDir::new(&abspath) { if handler.load(Ordering::SeqCst) { let path = entry.unwrap().into_path(); if !path.is_file() { continue; } if path.extension().is_some_and(|x| x == "flac") { - paths.push(path); - #[cfg(not(test))] bar.inc_length(1); } @@ -109,24 +105,25 @@ pub fn index_files_recursively( } } - paths.par_iter().for_each(|file| { + let conn = Database::new(pool.get()?); + for entry in WalkDir::new(abspath) { if handler.load(Ordering::SeqCst) { - let conn = match pool.get() { - Ok(conn) => Database::new(conn), - Err(error) => { - eprintln!("{}", FileError::new(file, error.into())); - return; + let path = entry.unwrap().into_path(); + if !path.is_file() { + continue; + } + if path.extension().is_some_and(|x| x == "flac") { + if let Err(error) = handle_file(&path, &conn) { + eprintln!("{}", FileError::new(path, error)); + } else { + #[cfg(not(test))] + bar.inc(1); } - }; - - if let Err(error) = handle_file(file, &conn) { - eprintln!("{}", FileError::new(file, error)) - } else { - #[cfg(not(test))] - bar.inc(1); } + } else { + break; } - }); + } #[cfg(not(test))] { -- cgit v1.3.1