diff options
| author | jakka <jakkadoujin@gmail.com> | 2025-07-02 19:33:32 +0300 |
|---|---|---|
| committer | jakka <jakkadoujin@gmail.com> | 2025-07-02 19:33:32 +0300 |
| commit | e767a0b6b922f71e3813e269b2c6a1412f15ccd4 (patch) | |
| tree | d1f70893408e23bdbc0f3ab60eb60c5d0ddf5dd7 | |
| parent | e38439f8012eabcd827c5abb7b7448a525feaf98 (diff) | |
made indexing single-threaded so db doesnt panic and no performance decrease
| -rw-r--r-- | src/files.rs | 35 | ||||
| -rw-r--r-- | src/main.rs | 2 |
2 files changed, 17 insertions, 20 deletions
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))] { diff --git a/src/main.rs b/src/main.rs index 6d0a3d4..1363a77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,7 @@ fn main() -> Result<()> { if let Some(realpath) = path { let hanlder = running.clone(); - pool.install(|| files::index_files_recursively(realpath, &dbpool, hanlder))?; + files::index_files_recursively(realpath, &dbpool, hanlder)?; } if args.get_flag("clean") { |
