From 8eef51afeb3abb22aa78e6f3f057971475dabf5e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 19 Apr 2022 13:19:54 +0200 Subject: [PATCH] Introduce IcingaDB::AddKvsToMap() --- lib/icingadb/icingadb-objects.cpp | 13 +------------ lib/icingadb/icingadb.hpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index ac876b61b..b1e759f99 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -230,18 +230,7 @@ void IcingaDB::UpdateAllConfigObjects() "HSCAN", configCheckSum, cursor, "COUNT", "1000" }, Prio::Config); - Array::Ptr kvs = res->Get(1); - Value* key = nullptr; - ObjectLock oLock (kvs); - - for (auto& kv : kvs) { - if (key) { - redisCheckSums.emplace(std::move(*key), std::move(kv)); - key = nullptr; - } else { - key = &kv; - } - } + AddKvsToMap(res->Get(1), redisCheckSums); cursor = res->Get(0); } while (cursor != "0"); diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index ef4483a7a..9e5525193 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -45,6 +45,22 @@ public: String GetEnvironmentId() const override; + template + static void AddKvsToMap(const Array::Ptr& kvs, T& map) + { + Value* key = nullptr; + ObjectLock oLock (kvs); + + for (auto& kv : kvs) { + if (key) { + map.emplace(std::move(*key), std::move(kv)); + key = nullptr; + } else { + key = &kv; + } + } + } + protected: void ValidateTlsProtocolmin(const Lazy& lvalue, const ValidationUtils& utils) override; void ValidateConnectTimeout(const Lazy& lvalue, const ValidationUtils& utils) override;