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;