From 5baef3c4a3b947d3275e9ce44cfb7a68984f6cca Mon Sep 17 00:00:00 2001 From: saturneric Date: Fri, 19 Jan 2024 21:54:26 +0800 Subject: fix: solve discovered bugs and improve ui operations --- src/core/function/gpg/GpgKeyGetter.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/core/function/gpg/GpgKeyGetter.cpp') diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index e22979d7..4a35d3cd 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -77,17 +77,16 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { } auto FetchKey() -> KeyLinkListPtr { - if (keys_cache_.empty()) { + if (keys_search_cache_.empty()) { FlushKeyCache(); } auto keys_list = std::make_unique(); - { // get the lock std::lock_guard lock(keys_cache_mutex_); - for (const auto& [key, value] : keys_cache_) { - keys_list->push_back(value); + for (const auto& key : keys_cache_) { + keys_list->push_back(key); } } return keys_list; @@ -98,6 +97,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { // clear the keys cache keys_cache_.clear(); + keys_search_cache_.clear(); // init GpgError err = gpgme_op_keylist_start(ctx_.DefaultContext(), nullptr, 0); @@ -123,12 +123,14 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { gpg_key = GetKey(gpg_key.GetId(), false); } - keys_cache_.insert({gpg_key.GetId(), std::move(gpg_key)}); + keys_cache_.push_back(gpg_key); + keys_search_cache_.insert(gpg_key.GetId(), gpg_key); + keys_search_cache_.insert(gpg_key.GetFingerprint(), gpg_key); } } GF_CORE_LOG_DEBUG("flush key channel cache address: {} object address: {}", - static_cast(&keys_cache_), + static_cast(&keys_search_cache_), static_cast(this)); // for debug @@ -181,7 +183,13 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { * @brief cache the keys with key id * */ - std::map keys_cache_; + QMap keys_search_cache_; + + /** + * @brief + * + */ + QList keys_cache_; /** * @brief shared mutex for the keys cache @@ -197,10 +205,10 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject { */ auto get_key_in_cache(const QString& key_id) -> GpgKey { std::lock_guard lock(keys_cache_mutex_); - if (keys_cache_.find(key_id) != keys_cache_.end()) { + if (keys_search_cache_.find(key_id) != keys_search_cache_.end()) { std::lock_guard lock(ctx_mutex_); // return a copy of the key in cache - return keys_cache_[key_id]; + return keys_search_cache_[key_id]; } // return a bad key -- cgit v1.2.3