Skip to content

Commit

Permalink
VolatileStateResults: Optimize and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Nov 19, 2024
1 parent f8dc85e commit e5c0925
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions library/Icingadb/Redis/VolatileStateResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Icingadb\Model\DependencyNode;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Module\Icingadb\Model\Service;
use Icinga\Module\Icingadb\Model\State;
use ipl\Orm\Query;
use ipl\Orm\Resolver;
use ipl\Orm\ResultSet;
Expand Down Expand Up @@ -107,6 +108,10 @@ protected function applyRedisUpdates($rows)
$type = null;
$showSourceGranted = $this->getAuth()->hasPermission('icingadb/object/show-source');

$getKeysAndBehaviors = function (State $state): array {
return [$state->getColumns(), $this->resolver->getBehaviors($state)];
};

$states = [];
$serviceHostStates = [];
foreach ($rows as $row) {
Expand All @@ -133,25 +138,25 @@ protected function applyRedisUpdates($rows)
}
}

if (! isset($states[$type]['behaviors'])) {
$states[$type]['behaviors'] = $this->resolver->getBehaviors($row->state);
}

$states[$type][bin2hex($row->id)] = $row->state;

if (! isset($states[$type]['keys'])) {
$keys = $row->state->getColumns();
[$keys, $behaviors] = $getKeysAndBehaviors($row->state);
if (! $showSourceGranted) {
$keys = array_diff($keys, ['check_commandline']);
}

$states[$type]['keys'] = $keys;
$states[$type]['behaviors'] = $behaviors;
}

if ($type === self::TYPE_SERVICE && $row->host instanceof Host && isset($row->host->id)) {
$serviceHostStates[bin2hex($row->host->id)] = $row->host->state;

if (! isset($serviceHostStates['keys'])) {
$serviceHostStates['keys'] = $row->host->state->getColumns();
$serviceHostStates['behaviors'] = $this->resolver->getBehaviors($row->host->state);
[$keys, $behaviors] = $getKeysAndBehaviors($row->host->state);
$serviceHostStates['keys'] = $keys;
$serviceHostStates['behaviors'] = $behaviors;
}
}
}
Expand Down

0 comments on commit e5c0925

Please sign in to comment.