Use cache for thumbnail too.
This commit is contained in:
parent
58064a6309
commit
e7b29509e5
@ -137,7 +137,10 @@ impl Library {
|
|||||||
let mut c = c.lock().unwrap();
|
let mut c = c.lock().unwrap();
|
||||||
match c.get(media_items_id) {
|
match c.get(media_items_id) {
|
||||||
Some(bytes) => {
|
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)?;
|
fs::write(&download_path, bytes)?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@ -220,17 +223,36 @@ impl Library {
|
|||||||
Ok(Some(bytes)) => Some(bytes),
|
Ok(Some(bytes)) => Some(bytes),
|
||||||
// Cache miss, fill cache and return.
|
// Cache miss, fill cache and return.
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
info!("cache MISS {}", key);
|
// TODO(wathiede): use cache for thumbnail like download_image does.
|
||||||
let bytes = match self.generate_thumbnail(
|
let c = Arc::clone(&self.image_cache);
|
||||||
media_items_id,
|
let mut c = c.lock().unwrap();
|
||||||
dimensions,
|
let bytes = match c.get(&key) {
|
||||||
FilterType::Builtin(imageops::FilterType::Lanczos3),
|
Some(bytes) => {
|
||||||
fill,
|
info!(
|
||||||
) {
|
"saving local copy of thumbnail from cache {}",
|
||||||
Ok(bytes) => bytes,
|
media_items_id
|
||||||
Err(e) => {
|
);
|
||||||
error!("Failed to generate thumbnail for {}: {}", media_items_id, e);
|
bytes
|
||||||
return None;
|
}
|
||||||
|
None => {
|
||||||
|
info!("cache MISS {}", key);
|
||||||
|
let bytes = match self.generate_thumbnail(
|
||||||
|
media_items_id,
|
||||||
|
dimensions,
|
||||||
|
FilterType::Builtin(imageops::FilterType::Lanczos3),
|
||||||
|
fill,
|
||||||
|
) {
|
||||||
|
Ok(bytes) => bytes,
|
||||||
|
Err(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) {
|
match db.put(key.as_bytes(), &bytes) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user