IcingaObject: Do not invalidate templateResolver on every setImports()

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

refs #11803
This commit is contained in:
Markus Frosch 2016-10-26 16:15:57 +02:00
parent 22802114ac
commit 86d2f317ee
3 changed files with 19 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}