From: Gunnar Beutner Date: Fri, 25 Jan 2013 11:46:49 +0000 (+0100) Subject: Performance improvements for *Group::GetMembers(). X-Git-Tag: v0.0.2~650 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b79f966b53cdf3292de6e87e6c7fbae17e536cfa;p=icinga2 Performance improvements for *Group::GetMembers(). --- diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 37904643a..bea0aee98 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -21,7 +21,7 @@ using namespace icinga; -map > Host::m_ServicesCache; +map > Host::m_ServicesCache; bool Host::m_ServicesCacheValid = true; static AttributeDescription hostAttributes[] = { @@ -295,11 +295,12 @@ set Host::GetServices(void) const ValidateServicesCache(); - BOOST_FOREACH(const String& svc, m_ServicesCache[GetName()]) { - if (!Service::Exists(svc)) + BOOST_FOREACH(const Service::WeakPtr& svc, m_ServicesCache[GetName()]) { + Service::Ptr service = svc.lock(); + + if (!service) continue; - Service::Ptr service = Service::GetByName(svc); services.insert(service); } @@ -323,7 +324,7 @@ void Host::ValidateServicesCache(void) BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) { const Service::Ptr& service = static_pointer_cast(object); - m_ServicesCache[service->GetHost()->GetName()].push_back(service->GetName()); + m_ServicesCache[service->GetHost()->GetName()].push_back(service); } m_ServicesCacheValid = true; diff --git a/lib/icinga/host.h b/lib/icinga/host.h index 37459c669..f57bc1a66 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -59,7 +59,7 @@ protected: private: static bool m_InitializerDone; - static map > m_ServicesCache; + static map > > m_ServicesCache; static bool m_ServicesCacheValid; static void ObjectCommittedHandler(const ConfigItem::Ptr& item); diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index fc94a2fae..debd7bdde 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -21,7 +21,7 @@ using namespace icinga; -map > HostGroup::m_MembersCache; +map > HostGroup::m_MembersCache; bool HostGroup::m_MembersCacheValid = true; static AttributeDescription hostGroupAttributes[] = { @@ -73,11 +73,12 @@ set HostGroup::GetMembers(void) const ValidateMembersCache(); - BOOST_FOREACH(const String& hst, m_MembersCache[GetName()]) { - if (!Host::Exists(hst)) + BOOST_FOREACH(const Host::WeakPtr& hst, m_MembersCache[GetName()]) { + Host::Ptr host = hst.lock(); + + if (!host) continue; - Host::Ptr host = Host::GetByName(hst); hosts.insert(host); } @@ -110,7 +111,7 @@ void HostGroup::ValidateMembersCache(void) if (!HostGroup::Exists(hostgroup)) Logger::Write(LogWarning, "icinga", "Host group '" + static_cast(hostgroup) + "' used but not defined."); - m_MembersCache[hostgroup].push_back(host->GetName()); + m_MembersCache[hostgroup].push_back(host); } } } diff --git a/lib/icinga/hostgroup.h b/lib/icinga/hostgroup.h index 9f921cf0b..4c6079a44 100644 --- a/lib/icinga/hostgroup.h +++ b/lib/icinga/hostgroup.h @@ -49,7 +49,7 @@ public: static void InvalidateMembersCache(void); private: - static map > m_MembersCache; + static map > > m_MembersCache; static bool m_MembersCacheValid; static void ValidateMembersCache(void); diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index ab323f03c..942e121e6 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -21,7 +21,7 @@ using namespace icinga; -map > ServiceGroup::m_MembersCache; +map > ServiceGroup::m_MembersCache; bool ServiceGroup::m_MembersCacheValid; static AttributeDescription serviceGroupAttributes[] = { @@ -73,11 +73,12 @@ set ServiceGroup::GetMembers(void) const ValidateMembersCache(); - BOOST_FOREACH(const String& svc, m_MembersCache[GetName()]) { - if (!Service::Exists(svc)) + BOOST_FOREACH(const Service::WeakPtr& svc, m_MembersCache[GetName()]) { + Service::Ptr service = svc.lock(); + + if (!service) continue; - Service::Ptr service = Service::GetByName(svc); services.insert(service); } @@ -110,7 +111,7 @@ void ServiceGroup::ValidateMembersCache(void) if (!ServiceGroup::Exists(servicegroup)) Logger::Write(LogWarning, "icinga", "Service group '" + static_cast(servicegroup) + "' used but not defined."); - m_MembersCache[servicegroup].push_back(service->GetName()); + m_MembersCache[servicegroup].push_back(service); } } } diff --git a/lib/icinga/servicegroup.h b/lib/icinga/servicegroup.h index 6798c69c6..c8dbd8da8 100644 --- a/lib/icinga/servicegroup.h +++ b/lib/icinga/servicegroup.h @@ -49,7 +49,7 @@ public: static void InvalidateMembersCache(void); private: - static map > m_MembersCache; + static map > > m_MembersCache; static bool m_MembersCacheValid; static void ValidateMembersCache(void);