]> granicus.if.org Git - icinga2/commitdiff
Performance improvements for *Group::GetMembers().
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 25 Jan 2013 11:46:49 +0000 (12:46 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 25 Jan 2013 11:46:49 +0000 (12:46 +0100)
lib/icinga/host.cpp
lib/icinga/host.h
lib/icinga/hostgroup.cpp
lib/icinga/hostgroup.h
lib/icinga/servicegroup.cpp
lib/icinga/servicegroup.h

index 37904643a95f0a46dd4fd2c8d6ea856147c4c531..bea0aee9818d793c53dd34e8ac087b5fc214bb1d 100644 (file)
@@ -21,7 +21,7 @@
 
 using namespace icinga;
 
-map<String, vector<String> > Host::m_ServicesCache;
+map<String, vector<Service::WeakPtr> > Host::m_ServicesCache;
 bool Host::m_ServicesCacheValid = true;
 
 static AttributeDescription hostAttributes[] = {
@@ -295,11 +295,12 @@ set<Service::Ptr> 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<Service>(object);
 
-               m_ServicesCache[service->GetHost()->GetName()].push_back(service->GetName());
+               m_ServicesCache[service->GetHost()->GetName()].push_back(service);
        }
 
        m_ServicesCacheValid = true;
index 37459c6698778bb5594ae755d9799222dc78ed1d..f57bc1a66737089bc5477e9a39d97fc383e85dde 100644 (file)
@@ -59,7 +59,7 @@ protected:
 private:
        static bool m_InitializerDone;
 
-       static map<String, vector<String> > m_ServicesCache;
+       static map<String, vector<weak_ptr<Service> > > m_ServicesCache;
        static bool m_ServicesCacheValid;
 
        static void ObjectCommittedHandler(const ConfigItem::Ptr& item);
index fc94a2faed783bd12fdbfd84972f8c1a06bcbfa0..debd7bdde684decf576154806850b3e8c176e0b6 100644 (file)
@@ -21,7 +21,7 @@
 
 using namespace icinga;
 
-map<String, vector<String> > HostGroup::m_MembersCache;
+map<String, vector<Host::WeakPtr> > HostGroup::m_MembersCache;
 bool HostGroup::m_MembersCacheValid = true;
 
 static AttributeDescription hostGroupAttributes[] = {
@@ -73,11 +73,12 @@ set<Host::Ptr> 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<String>(hostgroup) + "' used but not defined.");
 
-                               m_MembersCache[hostgroup].push_back(host->GetName());
+                               m_MembersCache[hostgroup].push_back(host);
                        }
                }
        }
index 9f921cf0b1e6507bebc2ab65a2e45ec8a471d26b..4c6079a44ca340a8d5515ab21e78ab9b31501de9 100644 (file)
@@ -49,7 +49,7 @@ public:
        static void InvalidateMembersCache(void);
 
 private:
-       static map<String, vector<String> > m_MembersCache;
+       static map<String, vector<weak_ptr<Host> > > m_MembersCache;
        static bool m_MembersCacheValid;
 
        static void ValidateMembersCache(void);
index ab323f03cfd0496566d3e45e08d712f14c1d680c..942e121e68b00f6533eed7e8f122bc9aa0999201 100644 (file)
@@ -21,7 +21,7 @@
 
 using namespace icinga;
 
-map<String, vector<String> > ServiceGroup::m_MembersCache;
+map<String, vector<Service::WeakPtr> > ServiceGroup::m_MembersCache;
 bool ServiceGroup::m_MembersCacheValid;
 
 static AttributeDescription serviceGroupAttributes[] = {
@@ -73,11 +73,12 @@ set<Service::Ptr> 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<String>(servicegroup) + "' used but not defined.");
 
-                               m_MembersCache[servicegroup].push_back(service->GetName());
+                               m_MembersCache[servicegroup].push_back(service);
                        }
                }
        }
index 6798c69c6f074ca5a2d56a09d622dad014e87912..c8dbd8da81c3c3894d5b08339eb7743e51c9fbd5 100644 (file)
@@ -49,7 +49,7 @@ public:
        static void InvalidateMembersCache(void);
 
 private:
-       static map<String, vector<String> > m_MembersCache;
+       static map<String, vector<weak_ptr<Service> > > m_MembersCache;
        static bool m_MembersCacheValid;
 
        static void ValidateMembersCache(void);