IcingaObject: introduce getSingleResolvedProperty()
Motivation: getResolvedProperty() has the effect that objects will fully resolve all inherited properties, vars and fields. This is overkill in situations where only a few resolves properties are needed and has quite an influence on overall rendering performance. Over time we might completely fade out that part of our resolving logic as it predates current cache implementations. Meanwhile, we keep two methods for two (internal) purposes.
This commit is contained in:
parent
a6928a8bc1
commit
913d934762
|
@ -83,7 +83,7 @@ class IcingaCommand extends IcingaObject
|
|||
$itlImport = '';
|
||||
}
|
||||
|
||||
$execute = $this->getResolvedProperty('methods_execute');
|
||||
$execute = $this->getSingleResolvedProperty('methods_execute');
|
||||
if ($execute === 'PluginNotification') {
|
||||
return $this->renderObjectHeaderWithType('NotificationCommand') . $itlImport;
|
||||
} elseif ($execute === 'PluginEvent') {
|
||||
|
|
|
@ -152,7 +152,7 @@ class IcingaHost extends IcingaObject
|
|||
|
||||
public function getCheckCommand()
|
||||
{
|
||||
$id = $this->getResolvedProperty('check_command_id');
|
||||
$id = $this->getSingleResolvedProperty('check_command_id');
|
||||
return IcingaCommand::loadWithAutoIncId(
|
||||
$id,
|
||||
$this->getConnection()
|
||||
|
@ -161,7 +161,7 @@ class IcingaHost extends IcingaObject
|
|||
|
||||
public function hasCheckCommand()
|
||||
{
|
||||
return $this->getResolvedProperty('check_command_id') !== null;
|
||||
return $this->getSingleResolvedProperty('check_command_id') !== null;
|
||||
}
|
||||
|
||||
public function renderToConfig(IcingaConfig $config)
|
||||
|
@ -185,7 +185,7 @@ class IcingaHost extends IcingaObject
|
|||
return;
|
||||
}
|
||||
|
||||
if ($this->getResolvedProperty('has_agent') !== 'y') {
|
||||
if ($this->getSingleResolvedProperty('has_agent') !== 'y') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -200,11 +200,11 @@ class IcingaHost extends IcingaObject
|
|||
'log_duration' => 0
|
||||
);
|
||||
|
||||
if ($this->getResolvedProperty('master_should_connect') === 'y') {
|
||||
$props['host'] = $this->getResolvedProperty('address');
|
||||
if ($this->getSingleResolvedProperty('master_should_connect') === 'y') {
|
||||
$props['host'] = $this->getSingleResolvedProperty('address');
|
||||
}
|
||||
|
||||
$props['zone_id'] = $this->getResolvedProperty('zone_id');
|
||||
$props['zone_id'] = $this->getSingleResolvedProperty('zone_id');
|
||||
|
||||
$endpoint = IcingaEndpoint::create($props);
|
||||
|
||||
|
|
|
@ -309,7 +309,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
|
||||
public function getResolvedRelated($property)
|
||||
{
|
||||
$id = $this->getResolvedProperty($property . '_id');
|
||||
$id = $this->getSingleResolvedProperty($property . '_id');
|
||||
|
||||
if ($id) {
|
||||
return $this->getRelatedObject($property, $id);
|
||||
|
@ -1059,6 +1059,30 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
$this->templateResolver()->listResolvedParentIds();
|
||||
}
|
||||
|
||||
public function getSingleResolvedProperty($key, $default = null)
|
||||
{
|
||||
if (array_key_exists($key, $this->unresolvedRelatedProperties)) {
|
||||
$this->resolveUnresolvedRelatedProperty($key);
|
||||
$this->invalidateResolveCache();
|
||||
}
|
||||
|
||||
if ($my = $this->get($key)) {
|
||||
if ($my !== null) {
|
||||
return $my;
|
||||
}
|
||||
}
|
||||
|
||||
/** @var IcingaObject $object */
|
||||
foreach (array_reverse($this->imports()->getObjects()) as $object) {
|
||||
$v = $object->getSingleResolvedProperty($key);
|
||||
if (null !== $v) {
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
protected function resolve($what)
|
||||
{
|
||||
if ($this->hasResolveCached($what)) {
|
||||
|
@ -1488,7 +1512,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
$deploymentMode = $config->getDeploymentMode();
|
||||
if ($deploymentMode === 'active-passive') {
|
||||
if (
|
||||
$this->getResolvedProperty('zone_id')
|
||||
$this->getSingleResolvedProperty('zone_id')
|
||||
&& array_key_exists('enable_active_checks', $this->defaultProperties)
|
||||
) {
|
||||
$passive = clone($this);
|
||||
|
@ -1559,7 +1583,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
}
|
||||
|
||||
try {
|
||||
if ($zoneId = $this->getResolvedProperty('zone_id')) {
|
||||
if ($zoneId = $this->getSingleResolvedProperty('zone_id')) {
|
||||
// Config has a lookup cache, is faster:
|
||||
return $config->getZoneName($zoneId);
|
||||
}
|
||||
|
@ -2592,7 +2616,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||
$props[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($this->supportsCustomVars()) {
|
||||
$props['vars'] = (object) array();
|
||||
foreach ($this->vars()->getOriginalVars() as $name => $var) {
|
||||
|
|
|
@ -103,7 +103,7 @@ class IcingaService extends IcingaObject
|
|||
|
||||
public function getCheckCommand()
|
||||
{
|
||||
$id = $this->getResolvedProperty('check_command_id');
|
||||
$id = $this->getSingleResolvedProperty('check_command_id');
|
||||
return IcingaCommand::loadWithAutoIncId(
|
||||
$id,
|
||||
$this->getConnection()
|
||||
|
@ -388,7 +388,7 @@ class IcingaService extends IcingaObject
|
|||
|
||||
public function hasCheckCommand()
|
||||
{
|
||||
return $this->getResolvedProperty('check_command_id') !== null;
|
||||
return $this->getSingleResolvedProperty('check_command_id') !== null;
|
||||
}
|
||||
|
||||
public function getOnDeleteUrl()
|
||||
|
|
Loading…
Reference in New Issue