Commit af2e5894 authored by Jordan Williams's avatar Jordan Williams Committed by Jordan Petridis
Browse files

Pass the valid duration into is_cached_image_valid

This makes the function extremely easy to test.
Additionally, the default valid duration is now a static constant.
parent 2e28b016
......@@ -190,14 +190,13 @@ impl ShowCoverModel {
/// Determine whether a cached image is valid.
/// A cached image is valid for a maximum of 4 weeks from the time of its previous download.
/// Otherwise, a cached image is only valid so long as the hash of its URI remains unchanged.
pub fn is_cached_image_valid(&self) -> bool {
let cache_valid_duration = Duration::weeks(4);
/// A cached image is valid from the time of its previous download for the given length of time.
/// Otherwise, a cached image is invalidated when the hash of its URI has changed.
pub fn is_cached_image_valid(&self, valid: &Duration) -> bool {
if Utc::now()
> cache_valid_duration
> *valid
return false;
......@@ -305,6 +305,7 @@ lazy_static! {
static ref COVER_DL_REGISTRY: RwLock<HashSet<i32>> = RwLock::new(HashSet::new());
static ref THREADPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap();
static ref CACHE_VALID_DURATION: chrono::Duration = chrono::Duration::weeks(4);
// Since gdk_pixbuf::Pixbuf is reference counted and every episode,
......@@ -319,7 +320,7 @@ pub(crate) fn set_image_from_path(image: &gtk::Image, show_id: i32, size: u32) -
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(show_id) {
// If the image is still valid, check if the requested (cover + size) is already in the
// cache and if so do an early return after that.
if pd.is_cached_image_valid() {
if pd.is_cached_image_valid(&CACHE_VALID_DURATION) {
if let Some(guard) = hashmap.get(&(show_id, size)) {
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