]> granicus.if.org Git - icinga2/commitdiff
Speed up config compiler.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Dec 2013 08:59:21 +0000 (09:59 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Dec 2013 08:59:21 +0000 (09:59 +0100)
Fixes #5255

lib/base/serializer.cpp
lib/base/type.h
lib/config/configitem.cpp
lib/config/configitem.h
lib/config/configtype.cpp

index 22156084de316dfe593545768c596b5744381131..a23450c63534cc77f7bdb390b8731247b9fbb5be 100644 (file)
@@ -167,11 +167,13 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary
                if ((field.Attributes & attributeTypes) == 0)
                        continue;
 
-               if (!input->Contains(field.Name))
+               Value value = input->Get(field.Name);
+
+               if (value.IsEmpty())
                        continue;
 
                try {
-                       instance->SetField(i, Deserialize(input->Get(field.Name), attributeTypes));
+                       instance->SetField(i, Deserialize(value, attributeTypes));
                } catch (const std::exception&) {
                        instance->SetField(i, Empty);
                }
index 0821247b9696802a8ddb101ce8662b840a585218..b508a153876b07aa2c51e66f8b90e2a237927a1b 100644 (file)
@@ -32,10 +32,10 @@ namespace icinga
 struct Field
 {
        int ID;
-       String Name;
+       const char *Name;
        int Attributes;
 
-       Field(int id, const String& name, int attributes)
+       Field(int id, const char *name, int attributes)
                : ID(id), Name(name), Attributes(attributes)
        { }
 };
index 3e8bc90c59d8bc9cf9ffe2b595a0fbd2a8cb0f19..b7287331b4447eb2d94243e8dbfc902f6bccaf83 100644 (file)
@@ -105,6 +105,9 @@ void ConfigItem::Link(void)
 {
        ObjectLock olock(this);
 
+       if (m_LinkedExpressionList)
+               return;
+
        m_LinkedExpressionList = make_shared<ExpressionList>();
 
        BOOST_FOREACH(const String& name, m_ParentNames) {
@@ -118,7 +121,7 @@ void ConfigItem::Link(void)
                } else {
                        parent->Link();
 
-                       ExpressionList::Ptr pexprl = parent->GetLinkedExpressionList();
+                       ExpressionList::Ptr pexprl = parent->m_LinkedExpressionList;
                        m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, pexprl, m_DebugInfo));
                }
        }
@@ -126,15 +129,26 @@ void ConfigItem::Link(void)
        m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, m_ExpressionList, m_DebugInfo));
 }
 
-ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void) const
+ExpressionList::Ptr ConfigItem::GetLinkedExpressionList(void)
 {
-       ObjectLock olock(this);
+       if (!m_LinkedExpressionList)
+               Link();
 
        return m_LinkedExpressionList;
 }
 
+Dictionary::Ptr ConfigItem::GetProperties(void)
+{
+       if (!m_Properties) {
+               m_Properties = make_shared<Dictionary>();
+               GetLinkedExpressionList()->Execute(m_Properties);
+       }
+
+       return m_Properties;
+}
+
 /**
- * Commits the configuration item by creating or updating a DynamicObject
+ * Commits the configuration item by creating a DynamicObject
  * object.
  *
  * @returns The DynamicObject that was created/updated.
@@ -157,24 +171,9 @@ DynamicObject::Ptr ConfigItem::Commit(void)
        if (IsAbstract())
                return DynamicObject::Ptr();
 
-       /* Create a fake update in the format that
-        * DynamicObject::Deserialize expects. */
-       Dictionary::Ptr attrs = make_shared<Dictionary>();
-
-       Link();
-
-       Dictionary::Ptr properties = make_shared<Dictionary>();
-       GetLinkedExpressionList()->Execute(properties);
+       Dictionary::Ptr properties = GetProperties();
 
-       {
-               ObjectLock olock(properties);
-
-               BOOST_FOREACH(const Dictionary::Pair& kv, properties) {
-                       attrs->Set(kv.first, kv.second);
-               }
-       }
-
-       DynamicObject::Ptr dobj = dtype->CreateObject(attrs);
+       DynamicObject::Ptr dobj = dtype->CreateObject(properties);
        dobj->Register();
 
        return dobj;
@@ -238,12 +237,6 @@ bool ConfigItem::ActivateItems(bool validateOnly)
        if (ConfigCompilerContext::GetInstance()->HasErrors())
                return false;
 
-       Log(LogInformation, "config", "Linking config items...");
-
-       BOOST_FOREACH(const ItemMap::value_type& kv, m_Items) {
-               kv.second->Link();
-       }
-
        if (ConfigCompilerContext::GetInstance()->HasErrors())
                return false;
 
index 6109f840c2a769773d081db54722750e14800200..98a65fdf28a483a803cd9516fa73b40b9c5dbb33 100644 (file)
@@ -48,9 +48,8 @@ public:
        std::vector<ConfigItem::Ptr> GetParents(void) const;
 
        void Link(void);
-       ExpressionList::Ptr GetLinkedExpressionList(void) const;
-
-       void GetProperties(void);
+       ExpressionList::Ptr GetLinkedExpressionList(void);
+       Dictionary::Ptr GetProperties(void);
 
        DynamicObject::Ptr Commit(void);
        void Register(void);
@@ -79,6 +78,7 @@ private:
        DebugInfo m_DebugInfo; /**< Debug information. */
 
        ExpressionList::Ptr m_LinkedExpressionList;
+       Dictionary::Ptr m_Properties;
 
        static boost::mutex m_Mutex;
 
index 3174e9516a44f463fdd7030c3a2467edb45ad768..5c18ddcfacee9d4082887be61b0d35ca59b3f195 100644 (file)
@@ -79,8 +79,7 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item)
        if (item->IsAbstract())
                return;
 
-       Dictionary::Ptr attrs = make_shared<Dictionary>();
-       item->GetLinkedExpressionList()->Execute(attrs);
+       Dictionary::Ptr attrs = item->GetProperties();
 
        std::vector<String> locations;
        DebugInfo debugInfo  = item->GetDebugInfo();