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.
This commit is contained in:
parent
822deb2867
commit
273c9f7b99
@ -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() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user