From fb98d3edef79b7171427aeabb2e1e377ceea55c0 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 25 Jul 2019 18:00:08 +0200 Subject: [PATCH] RedisConnection#ExecuteQuer{y,ies}(): std::move() queries refs #49 --- lib/redis/redisconnection.cpp | 19 ++++++++++++------- lib/redis/redisconnection.hpp | 4 ++-- lib/redis/rediswriter-objects.cpp | 10 +++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/redis/redisconnection.cpp b/lib/redis/redisconnection.cpp index 0849bce1b..32b4272ea 100644 --- a/lib/redis/redisconnection.cpp +++ b/lib/redis/redisconnection.cpp @@ -25,7 +25,8 @@ #include "base/utility.hpp" #include "redis/rediswriter.hpp" #include "hiredis/hiredis.h" - +#include +#include using namespace icinga; @@ -179,18 +180,22 @@ void RedisConnection::DisconnectCallback(const redisAsyncContext *c, int status) rc->m_Connected = false; } -void RedisConnection::ExecuteQuery(const std::vector& query, redisCallbackFn *fn, void *privdata) +void RedisConnection::ExecuteQuery(std::vector query, redisCallbackFn *fn, void *privdata) { - m_RedisConnectionWorkQueue.Enqueue([this, query, fn, privdata]() { - SendMessageInternal(query, fn, privdata); + auto queryPtr (std::make_shared(std::move(query))); + + m_RedisConnectionWorkQueue.Enqueue([this, queryPtr, fn, privdata]() { + SendMessageInternal(*queryPtr, fn, privdata); }); } void -RedisConnection::ExecuteQueries(const std::vector >& queries, redisCallbackFn *fn, void *privdata) +RedisConnection::ExecuteQueries(std::vector> queries, redisCallbackFn *fn, void *privdata) { - m_RedisConnectionWorkQueue.Enqueue([this, queries, fn, privdata]() { - SendMessagesInternal(queries, fn, privdata); + auto queriesPtr (std::make_shared(std::move(queries))); + + m_RedisConnectionWorkQueue.Enqueue([this, queriesPtr, fn, privdata]() { + SendMessagesInternal(*queriesPtr, fn, privdata); }); } diff --git a/lib/redis/redisconnection.hpp b/lib/redis/redisconnection.hpp index 4f1af40f7..7b1e21404 100644 --- a/lib/redis/redisconnection.hpp +++ b/lib/redis/redisconnection.hpp @@ -60,9 +60,9 @@ namespace icinga bool IsConnected(); - void ExecuteQuery(const std::vector& query, redisCallbackFn *fn = NULL, void *privdata = NULL); + void ExecuteQuery(std::vector query, redisCallbackFn *fn = NULL, void *privdata = NULL); - void ExecuteQueries(const std::vector >& queries, redisCallbackFn *fn = NULL, + void ExecuteQueries(std::vector> queries, redisCallbackFn *fn = NULL, void *privdata = NULL); private: diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 2b17216de..143bf671b 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -166,7 +166,7 @@ void RedisWriter::UpdateAllConfigObjects() if (transaction.size() > 1) { transaction.push_back({"EXEC"}); - m_Rcon->ExecuteQueries(transaction); + m_Rcon->ExecuteQueries(std::move(transaction)); transaction = {{"MULTI"}}; } } @@ -184,7 +184,7 @@ void RedisWriter::UpdateAllConfigObjects() if (transaction.size() > 1) { transaction.push_back({"EXEC"}); - m_Rcon->ExecuteQueries(transaction); + m_Rcon->ExecuteQueries(std::move(transaction)); } m_Rcon->ExecuteQuery({"PUBLISH", "icinga:config:dump", lcType}); @@ -249,7 +249,7 @@ void RedisWriter::DeleteKeys(const std::vector& keys) { query.emplace_back(key); } - m_Rcon->ExecuteQuery(query); + m_Rcon->ExecuteQuery(std::move(query)); } std::vector RedisWriter::GetTypeObjectKeys(const String& type) @@ -679,7 +679,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtime if (transaction.size() > 1) { transaction.push_back({"EXEC"}); - m_Rcon->ExecuteQueries(transaction); + m_Rcon->ExecuteQueries(std::move(transaction)); } } @@ -1008,7 +1008,7 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object) streamadd.emplace_back(kv.second); } - m_Rcon->ExecuteQuery(streamadd); + m_Rcon->ExecuteQuery(std::move(streamadd)); } Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable)