From 86d2f317ee7ec44d8a924d8e51ace253f44feba7 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Wed, 26 Oct 2016 16:15:57 +0200 Subject: [PATCH] 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 ---- .../Director/Objects/IcingaObjectImports.php | 1 + .../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 aec05378..101350fd 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 d351c868..3e285d4b 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 7b70abcf..31a913e8 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; + } }