Compare commits

...

1 commit

Author SHA1 Message Date
Polochon-street
898e2eea19 Remove parallel analysis 2021-06-25 16:26:57 +02:00

View file

@ -122,35 +122,14 @@ pub trait Library {
if paths.is_empty() { if paths.is_empty() {
return Ok(()); return Ok(());
} }
let num_cpus = num_cpus::get(); let mut songs = Vec::new();
for path in paths {
#[allow(clippy::type_complexity)] info!("Analyzing file '{}'", path);
let (tx, rx): ( let song = Song::new(&path);
Sender<(String, BlissResult<Song>)>, songs.push((path.to_string(), song));
Receiver<(String, BlissResult<Song>)>,
) = mpsc::channel();
let mut handles = Vec::new();
let mut chunk_length = paths.len() / num_cpus;
if chunk_length == 0 {
chunk_length = paths.len();
} }
for chunk in paths.chunks(chunk_length) { for (path, song) in songs {
let tx_thread = tx.clone();
let owned_chunk = chunk.to_owned();
let child = thread::spawn(move || {
for path in owned_chunk {
info!("Analyzing file '{}'", path);
let song = Song::new(&path);
tx_thread.send((path.to_string(), song)).unwrap();
}
drop(tx_thread);
});
handles.push(child);
}
drop(tx);
for (path, song) in rx.iter() {
// A storage fail should just warn the user, but not abort the whole process // A storage fail should just warn the user, but not abort the whole process
match song { match song {
Ok(song) => { Ok(song) => {
@ -174,12 +153,6 @@ pub trait Library {
} }
} }
} }
for child in handles {
child
.join()
.map_err(|_| BlissError::AnalysisError("in analysis".to_string()))?;
}
Ok(()) Ok(())
} }