[icinga-checkins] icinga.org: icingaweb2-module-director/bugfix/loop-templateresolver-11803: IcingaObject: Do not invalidate templateResolver on every setImports()

git at icinga.org git at icinga.org
Mon Oct 31 13:31:49 CET 2016


Module: icingaweb2-module-director
Branch: bugfix/loop-templateresolver-11803
Commit: c57d3c314e062e7aa303cf2045b21e07a5ffbef3
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=c57d3c314e062e7aa303cf2045b21e07a5ffbef3

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Wed Oct 26 16:15:57 2016 +0200

IcingaObject: Do not invalidate templateResolver on every setImports()

Do not clear templateResolver, but refresh current object with its "new" parents.

refs #11803

---

 library/Director/Objects/IcingaObject.php           |    4 ----
 library/Director/Objects/IcingaObjectImports.php    |    1 +
 library/Director/Objects/IcingaTemplateResolver.php |   18 ++++++++++++++++++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index aec0537..101350f 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -1005,10 +1005,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
     public function invalidateResolveCache()
     {
         $this->resolveCache = array();
-        if ($this->templateResolver) {
-            $this->templateResolver()->clearCache();
-        }
-
         return $this;
     }
 
diff --git a/library/Director/Objects/IcingaObjectImports.php b/library/Director/Objects/IcingaObjectImports.php
index d351c86..3e285d4 100644
--- a/library/Director/Objects/IcingaObjectImports.php
+++ b/library/Director/Objects/IcingaObjectImports.php
@@ -167,6 +167,7 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
     protected function refreshIndex()
     {
         $this->idx = array_keys($this->imports);
+        $this->object->templateResolver()->refreshObject($this->object);
         return $this;
     }
 
diff --git a/library/Director/Objects/IcingaTemplateResolver.php b/library/Director/Objects/IcingaTemplateResolver.php
index 7b70abc..31a913e 100644
--- a/library/Director/Objects/IcingaTemplateResolver.php
+++ b/library/Director/Objects/IcingaTemplateResolver.php
@@ -9,10 +9,13 @@ use Icinga\Module\Director\Exception\NestingError;
 // TODO: move the 'type' layer to another class
 class IcingaTemplateResolver
 {
+    /** @var IcingaObject */
     protected $object;
 
+    /** @var Db */
     protected $connection;
 
+    /** @var  \Zend_Db_Adapter_Abstract */
     protected $db;
 
     protected $type;
@@ -162,6 +165,11 @@ class IcingaTemplateResolver
         return $this->resolveParentIds();
     }
 
+    /**
+     * TODO: unfinished and not used currently
+     *
+     * @return array
+     */
     public function listResolvedParentNames()
     {
         $this->requireTemplates();
@@ -365,4 +373,14 @@ class IcingaTemplateResolver
         unset($this->db);
         unset($this->object);
     }
+
+    public function refreshObject(IcingaObject $object)
+    {
+        $parentNames = $object->imports;
+        self::$nameIdx[$object->object_name] = $parentNames;
+        if ($object->hasBeenLoadedFromDb()) {
+            self::$idIdx[$object->getId()] = $this->getIdsForNames($parentNames);
+        }
+        return $this;
+    }
 }



More information about the icinga-checkins mailing list