Commit 993b6e9d authored by Jordan Petridis's avatar Jordan Petridis 🌱 Committed by Jordan Petridis

Utils: only queue a single cover download

Before we were inserting the id of the cover into the registry
from a rayon thread. But rayon will only execute N threads at the
same time and let the rest into a queue. This would casue mutliple
jobs being queued since the cover id was not inserted in the
registry until the downloading had started.

This fixes said behavior by having the main thread block and write
in the id in the registry.
parent 273c9f7b
Pipeline #27285 passed with stages
in 31 minutes and 24 seconds
......@@ -285,20 +285,22 @@ pub(crate) fn set_image_from_path(
}
let (sender, receiver) = unbounded();
THREADPOOL.spawn(move || {
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
guard.insert(show_id);
}
// This operation is polling and will block the thread till the download is finished
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) {
sender.send(downloader::cache_image(&pd));
}
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
// Add the id to the hashmap from the main thread to avoid queuing more than one downloads.
guard.insert(show_id);
drop(guard);
THREADPOOL.spawn(move || {
// This operation is polling and will block the thread till the download is finished
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) {
sender.send(downloader::cache_image(&pd));
}
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
guard.remove(&show_id);
}
});
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
guard.remove(&show_id);
}
});
}
let image = image.clone();
let s = size as i32;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment