Commit 273c9f7b authored by Jordan Petridis's avatar Jordan Petridis 🌱 Committed by Jordan Petridis

Utils: Change the priority of the cover caches

Since loadign a pixbuf from the pre-rendered cache is the most
common operation and it does not affect the behavior we can
first check that and then if the cover is midway downloading.

This avoids a mutex lock for the most common path.
parent 822deb28
......@@ -251,21 +251,6 @@ pub(crate) fn set_image_from_path(
show_id: i32,
size: u32,
) -> Result<(), Error> {
// Check if there's an active download about this show cover.
// If there is, a callback will be set so this function will be called again.
// If the download succeeds, there should be a quick return from the pixbuf cache_image
// If it fails another download will be scheduled.
if let Ok(guard) = COVER_DL_REGISTRY.read() {
if guard.contains(&show_id) {
let callback = clone!(image => move || {
let _ = set_image_from_path(&image, show_id, size);
glib::Continue(false)
});
gtk::timeout_add(250, callback);
return Ok(());
}
}
if let Ok(hashmap) = CACHED_PIXBUFS.read() {
// Check if the requested (cover + size) is already in the cache
// and if so do an early return after that.
......@@ -284,6 +269,21 @@ pub(crate) fn set_image_from_path(
}
}
// Check if there's an active download about this show cover.
// If there is, a callback will be set so this function will be called again.
// If the download succeeds, there should be a quick return from the pixbuf cache_image
// If it fails another download will be scheduled.
if let Ok(guard) = COVER_DL_REGISTRY.read() {
if guard.contains(&show_id) {
let callback = clone!(image => move || {
let _ = set_image_from_path(&image, show_id, size);
glib::Continue(false)
});
gtk::timeout_add(250, callback);
return Ok(());
}
}
let (sender, receiver) = unbounded();
THREADPOOL.spawn(move || {
if let Ok(mut guard) = COVER_DL_REGISTRY.write() {
......
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