aboutsummaryrefslogtreecommitdiff
path: root/src/AsyncImageLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/AsyncImageLoader.cpp')
-rw-r--r--src/AsyncImageLoader.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index 4021c55..8613cf9 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -312,15 +312,19 @@ namespace QuickMedia {
}
std::shared_ptr<ThumbnailData> AsyncImageLoader::get_thumbnail(const std::string &url, bool local, mgl::vec2i resize_target_size) {
- // TODO: Instead of generating a new hash everytime to access thumbnail, cache the hash of the thumbnail url
- auto &thumbnail_data = thumbnails[url + "_" + std::to_string(resize_target_size.x) + "x" + std::to_string(resize_target_size.y)];
- if(!thumbnail_data)
+ // TODO: Instead of generating a new hash everytime to access thumbnail, cache the hash of the thumbnail url.
+ // TODO: Cache this resize_url
+ std::string resize_url = url + "_" + std::to_string(resize_target_size.x) + "x" + std::to_string(resize_target_size.y);
+ auto &thumbnail_data = thumbnails[resize_url];
+ if(!thumbnail_data) {
thumbnail_data = std::make_shared<ThumbnailData>();
+ thumbnail_data->url = url;
+ }
thumbnail_data->counter = counter;
if(thumbnail_data->thumbnail_path.data.empty()) {
SHA256 sha256;
- sha256.add(url.data(), url.size());
+ sha256.add(resize_url.data(), resize_url.size());
thumbnail_data->thumbnail_path = get_cache_dir().join("thumbnails").join(sha256.getHash());
}
@@ -358,7 +362,7 @@ namespace QuickMedia {
if(download.read_program.pid == -1)
continue;
- if(download.url == it->first) {
+ if(download.url == it->second->url) {
reset_download(download);
break;
}
@@ -366,7 +370,7 @@ namespace QuickMedia {
}
image_thumbnail_create_queue.erase_if([&it](ThumbnailLoadData &load_data) {
- return load_data.path.data == it->first;
+ return load_data.path.data == it->second->url;
});
it = thumbnails.erase(it);