metadata: cache recent files for faster operation

(cherry picked from commit 6ee014ddb7ab77537289e1f41f13345e5db54710)
This commit is contained in:
Alberto Griggio 2019-12-09 04:27:13 -08:00 committed by Lawrence Lee
parent e3f3b8ae91
commit e7fdad875a
No known key found for this signature in database
GPG Key ID: 048FF2B76A63895F
3 changed files with 31 additions and 16 deletions

View File

@ -21,6 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <iostream> #include <iostream>
#include <giomm.h>
#include "metadata.h" #include "metadata.h"
#include "settings.h" #include "settings.h"
@ -32,9 +33,12 @@ namespace rtengine {
extern const Settings *settings; extern const Settings *settings;
std::unique_ptr<Exiv2Metadata::ImageCache> Exiv2Metadata::cache_(nullptr);
namespace { namespace {
constexpr size_t IMAGE_CACHE_SIZE = 200;
Exiv2::Image::AutoPtr open_exiv2(const Glib::ustring& fname) Exiv2::Image::AutoPtr open_exiv2(const Glib::ustring& fname)
{ {
#ifdef EXV_UNICODE_PATH #ifdef EXV_UNICODE_PATH
@ -88,10 +92,19 @@ Exiv2Metadata::Exiv2Metadata(const Glib::ustring &path, bool merge_xmp_sidecar):
void Exiv2Metadata::load() const void Exiv2Metadata::load() const
{ {
if (!src_.empty() && !image_.get()) { 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_); auto img = open_exiv2(src_);
image_.reset(img.release()); image_.reset(img.release());
image_->readMetadata(); image_->readMetadata();
if (cache_) {
cache_->set(src_, CacheVal(image_, finfo->modification_time()));
}
}
if (merge_xmp_) { if (merge_xmp_) {
do_merge_xmp(image_.get()); do_merge_xmp(image_.get());
@ -319,6 +332,7 @@ Exiv2::XmpData Exiv2Metadata::getXmpSidecar(const Glib::ustring &path)
void Exiv2Metadata::init() void Exiv2Metadata::init()
{ {
cache_.reset(new ImageCache(IMAGE_CACHE_SIZE));
Exiv2::XmpParser::initialize(); Exiv2::XmpParser::initialize();
} }

View File

@ -24,6 +24,7 @@
#include <exiv2/exiv2.hpp> #include <exiv2/exiv2.hpp>
#include <memory> #include <memory>
#include "procparams.h" #include "procparams.h"
#include "cache.h"
namespace rtengine { namespace rtengine {
@ -74,11 +75,10 @@ private:
Exiv2::ExifData exif_data_; Exiv2::ExifData exif_data_;
Exiv2::IptcData iptc_data_; Exiv2::IptcData iptc_data_;
Exiv2::XmpData xmp_data_; Exiv2::XmpData xmp_data_;
typedef std::pair<std::shared_ptr<Exiv2::Image>, Glib::TimeVal> CacheVal;
typedef Cache<Glib::ustring, CacheVal> ImageCache;
static std::unique_ptr<ImageCache> cache_;
}; };
// Glib::ustring get_xmp_sidecar_path(const Glib::ustring &path);
// Exiv2::Image::AutoPtr open_exiv2(const Glib::ustring &fname,
// bool merge_xmp_sidecar);
// Exiv2::XmpData read_exiv2_xmp(const Glib::ustring &fname);
} // namespace rtengine } // namespace rtengine

View File

@ -1,4 +1,5 @@
/* /* -*- C++ -*-
*
* This file is part of RawTherapee. * This file is part of RawTherapee.
* *
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com> * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
@ -16,9 +17,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/ */
#define UNKNOWN -1 constexpr int UNKNOWN = -1;
#define FILEBROWSER 1 constexpr int FILEBROWSER = 1;
#define EDITOR 2 constexpr int EDITOR = 2;
#define BATCHEDITOR 3 constexpr int BATCHEDITOR = 3;
#define CACHEMGR 4 constexpr int CACHEMGR = 4;
#define SAFETYUPDATE 5 constexpr int SAFETYUPDATE = 5;