metadata: cache recent files for faster operation
(cherry picked from commit 6ee014ddb7ab77537289e1f41f13345e5db54710)
This commit is contained in:
committed by
Lawrence Lee
parent
e3f3b8ae91
commit
e7fdad875a
@@ -21,6 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <iostream>
|
||||
#include <giomm.h>
|
||||
|
||||
#include "metadata.h"
|
||||
#include "settings.h"
|
||||
@@ -32,9 +33,12 @@ namespace rtengine {
|
||||
|
||||
extern const Settings *settings;
|
||||
|
||||
std::unique_ptr<Exiv2Metadata::ImageCache> Exiv2Metadata::cache_(nullptr);
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr size_t IMAGE_CACHE_SIZE = 200;
|
||||
|
||||
Exiv2::Image::AutoPtr open_exiv2(const Glib::ustring& fname)
|
||||
{
|
||||
#ifdef EXV_UNICODE_PATH
|
||||
@@ -88,10 +92,19 @@ Exiv2Metadata::Exiv2Metadata(const Glib::ustring &path, bool merge_xmp_sidecar):
|
||||
|
||||
void Exiv2Metadata::load() const
|
||||
{
|
||||
if (!src_.empty() && !image_.get()) {
|
||||
auto img = open_exiv2(src_);
|
||||
image_.reset(img.release());
|
||||
image_->readMetadata();
|
||||
if (!src_.empty() && !image_.get() && Glib::file_test(src_.c_str(), Glib::FILE_TEST_EXISTS)) {
|
||||
CacheVal val;
|
||||
auto finfo = Gio::File::create_for_path(src_)->query_info(G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
||||
if (cache_ && cache_->get(src_, val) && val.second >= finfo->modification_time()) {
|
||||
image_ = val.first;
|
||||
} else {
|
||||
auto img = open_exiv2(src_);
|
||||
image_.reset(img.release());
|
||||
image_->readMetadata();
|
||||
if (cache_) {
|
||||
cache_->set(src_, CacheVal(image_, finfo->modification_time()));
|
||||
}
|
||||
}
|
||||
|
||||
if (merge_xmp_) {
|
||||
do_merge_xmp(image_.get());
|
||||
@@ -319,6 +332,7 @@ Exiv2::XmpData Exiv2Metadata::getXmpSidecar(const Glib::ustring &path)
|
||||
|
||||
void Exiv2Metadata::init()
|
||||
{
|
||||
cache_.reset(new ImageCache(IMAGE_CACHE_SIZE));
|
||||
Exiv2::XmpParser::initialize();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user