diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index 92aaba92f..770726a6a 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -138,7 +138,7 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary continue; try { - instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes)); + instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes), true); } catch (const std::exception&) { instance->SetField(fid, Empty); } diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index e9f5ca0fb..6f4af2da5 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -39,7 +39,8 @@ Timer::Ptr DbConnection::m_ProgramStatusTimer; boost::once_flag DbConnection::m_OnceFlag = BOOST_ONCE_INIT; DbConnection::DbConnection(void) - : m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0), m_IDCacheValid(false) + : m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0), + m_IDCacheValid(false), m_ActiveChangedHandler(false) { } void DbConnection::OnConfigLoaded(void) @@ -74,7 +75,14 @@ void DbConnection::Start(bool runtimeCreated) DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1)); DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1)); - ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1)); +} + +void DbConnection::EnableActiveChangedHandler(void) +{ + if (!m_ActiveChangedHandler) { + ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1)); + m_ActiveChangedHandler = true; + } } void DbConnection::StatsLoggerTimerHandler(void) @@ -394,8 +402,10 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object) bool dbActive = GetObjectActive(dbobj); bool active = object->IsActive(); - if (active && !dbActive) { - ActivateObject(dbobj); + if (active) { + if (!dbActive) + ActivateObject(dbobj); + dbobj->SendConfigUpdate(); dbobj->SendStatusUpdate(); } else if (!active) { diff --git a/lib/db_ido/dbconnection.hpp b/lib/db_ido/dbconnection.hpp index 842371994..74cc6b3e9 100644 --- a/lib/db_ido/dbconnection.hpp +++ b/lib/db_ido/dbconnection.hpp @@ -98,6 +98,8 @@ protected: bool IsIDCacheValid(void) const; void SetIDCacheValid(bool valid); + void EnableActiveChangedHandler(void); + static void UpdateProgramStatus(void); static int GetSessionToken(void); @@ -127,6 +129,7 @@ private: RingBuffer m_QueryStats; int m_PendingQueries; double m_PendingQueriesTimestamp; + bool m_ActiveChangedHandler; }; struct database_error : virtual std::exception, virtual boost::exception { }; diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 0c7165a69..3bc8e89bc 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -399,16 +399,16 @@ void IdoMysqlConnection::Reconnect(void) SetIDCacheValid(true); + EnableActiveChangedHandler(); + BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) { - if (dbobj->GetObject() == NULL) { - Log(LogNotice, "IdoMysqlConnection") - << "Deactivate deleted object name1: '" << dbobj->GetName1() - << "' name2: '" << dbobj->GetName2() + "'."; - DeactivateObject(dbobj); - } else { - dbobj->SendConfigUpdate(); - dbobj->SendStatusUpdate(); - } + if (dbobj->GetObject()) + continue; + + Log(LogNotice, "IdoMysqlConnection") + << "Deactivate deleted object name1: '" << dbobj->GetName1() + << "' name2: '" << dbobj->GetName2() + "'."; + DeactivateObject(dbobj); } UpdateAllObjects(); diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 55e2b98bd..9cc124232 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -372,16 +372,16 @@ void IdoPgsqlConnection::Reconnect(void) SetIDCacheValid(true); + EnableActiveChangedHandler(); + BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) { - if (dbobj->GetObject() == NULL) { - Log(LogNotice, "IdoPgsqlConnection") - << "Deactivate deleted object name1: '" << dbobj->GetName1() - << "' name2: '" << dbobj->GetName2() + "'."; - DeactivateObject(dbobj); - } else { - dbobj->SendConfigUpdate(); - dbobj->SendStatusUpdate(); - } + if (dbobj->GetObject()) + continue; + + Log(LogNotice, "IdoPgsqlConnection") + << "Deactivate deleted object name1: '" << dbobj->GetName1() + << "' name2: '" << dbobj->GetName2() + "'."; + DeactivateObject(dbobj); } UpdateAllObjects();