From 33a00e4b5a53765cae1518de937c0f5133b3c7bf Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 29 May 2018 12:54:14 +0200 Subject: [PATCH] Move UpdateObjectAttrs into the objects scope --- lib/redis/rediswriter-objects.cpp | 40 +++++++++++++++++++++++++++++++ lib/redis/rediswriter-utility.cpp | 40 ------------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index a6d44d1e1..fbbf86d5e 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -320,6 +320,46 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, bool useTran // } } +void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType) +{ + Type::Ptr type = object->GetReflectionType(); + + String typeName = type->GetName().ToLower(); + String objectName = object->GetName(); + + std::vector > queries; + + queries.push_back({ "DEL", keyPrefix + object->GetName() }); + + std::vector hmsetCommand({ "HMSET", keyPrefix + typeName + ":" + object->GetName() }); + + for (int fid = 0; fid < type->GetFieldCount(); fid++) { + Field field = type->GetFieldInfo(fid); + + if ((field.Attributes & fieldType) == 0) + continue; + + Value val = object->GetField(fid); + + /* hide attributes which shouldn't be user-visible */ + if (field.Attributes & FANoUserView) + continue; + + /* hide internal navigation fields */ + if (field.Attributes & FANavigation && !(field.Attributes & (FAConfig | FAState))) + continue; + + hmsetCommand.push_back(field.Name); + + Value sval = Serialize(val); + hmsetCommand.push_back(JsonEncode(sval)); + } + + queries.push_back(hmsetCommand); + + ExecuteQueries(queries); +} + void RedisWriter::StateChangedHandler(const ConfigObject::Ptr& object) { Type::Ptr type = object->GetReflectionType(); diff --git a/lib/redis/rediswriter-utility.cpp b/lib/redis/rediswriter-utility.cpp index d1aac8c5c..4c6b378ad 100644 --- a/lib/redis/rediswriter-utility.cpp +++ b/lib/redis/rediswriter-utility.cpp @@ -86,43 +86,3 @@ String RedisWriter::HashValue(const Value& value) return SHA1(JsonEncode(temp)); } -void RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr& object, int fieldType) -{ - Type::Ptr type = object->GetReflectionType(); - - String typeName = type->GetName(); - String objectName = object->GetName(); - - std::vector > queries; - - queries.push_back({ "DEL", keyPrefix + object->GetName() }); - - std::vector hmsetCommand({ "HMSET", keyPrefix + typeName + ":" + objectName }); - - for (int fid = 0; fid < type->GetFieldCount(); fid++) { - Field field = type->GetFieldInfo(fid); - - if ((field.Attributes & fieldType) == 0) - continue; - - Value val = object->GetField(fid); - - /* hide attributes which shouldn't be user-visible */ - if (field.Attributes & FANoUserView) - continue; - - /* hide internal navigation fields */ - if (field.Attributes & FANavigation && !(field.Attributes & (FAConfig | FAState))) - continue; - - hmsetCommand.push_back(field.Name); - - Value sval = Serialize(val); - hmsetCommand.push_back(JsonEncode(sval)); - } - - queries.push_back(hmsetCommand); - - ExecuteQueries(queries); -} -