Use cache for thumbnail too.

This commit is contained in:
Bill Thiede 2020-06-20 22:40:08 -07:00
parent 58064a6309
commit e7b29509e5

View File

@ -137,7 +137,10 @@ impl Library {
let mut c = c.lock().unwrap();
match c.get(media_items_id) {
Some(bytes) => {
info!("saving local copy from cache {}", media_items_id);
info!(
"saving local copy of original from cache {}",
media_items_id
);
fs::write(&download_path, bytes)?;
}
None => {
@ -220,6 +223,18 @@ impl Library {
Ok(Some(bytes)) => Some(bytes),
// Cache miss, fill cache and return.
Ok(None) => {
// TODO(wathiede): use cache for thumbnail like download_image does.
let c = Arc::clone(&self.image_cache);
let mut c = c.lock().unwrap();
let bytes = match c.get(&key) {
Some(bytes) => {
info!(
"saving local copy of thumbnail from cache {}",
media_items_id
);
bytes
}
None => {
info!("cache MISS {}", key);
let bytes = match self.generate_thumbnail(
media_items_id,
@ -229,10 +244,17 @@ impl Library {
) {
Ok(bytes) => bytes,
Err(e) => {
error!("Failed to generate thumbnail for {}: {}", media_items_id, e);
error!(
"Failed to generate thumbnail for {}: {}",
media_items_id, e
);
return None;
}
};
c.set(&key, &bytes);
bytes
}
};
match db.put(key.as_bytes(), &bytes) {
Ok(_) => Some(bytes),
Err(e) => {