Skip to content

Commit

Permalink
Unreachable parent optimizations (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Jan 15, 2025
2 parents 02ff5d8 + 0b51376 commit b52c219
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions library/Icingadb/Model/UnreachableParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Icingadb\Model;

use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
use Icinga\Module\Icingadb\Model\UnreachableParent\ResultSet;
use InvalidArgumentException;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behaviors;
Expand Down Expand Up @@ -112,6 +113,8 @@ public static function on(Connection $db, Model $root = null): Query
)
));

$query->setResultSetClass(ResultSet::class);

return $query;
}

Expand Down Expand Up @@ -161,10 +164,7 @@ private static function selectNodes(Connection $db, Model $root): Select
'redundancy_group_id' => 'to.redundancy_group_id',
'is_group_member' => new Expression('urn.redundancy_group_id IS NOT NULL AND urn.level > 0')
]);
$nodeQuery->filter(Filter::any(
Filter::equal('state.failed', 'y'),
Filter::equal('to.redundancy_group.state.failed', 'y')
));
$nodeQuery->filter(Filter::equal('state.failed', 'y'));

$nodeSelect = $nodeQuery->assembleSelect();

Expand Down
23 changes: 23 additions & 0 deletions library/Icingadb/Model/UnreachableParent/ResultSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Icinga\Module\Icingadb\Model\UnreachableParent;

use Icinga\Module\Icingadb\Redis\VolatileStateResults;
use Traversable;

class ResultSet extends VolatileStateResults
{
protected function yieldTraversable(Traversable $traversable)
{
$knownIds = [];
foreach ($traversable as $value) {
if (isset($knownIds[$value->id])) {
continue;
}

$knownIds[$value->id] = true;

yield $value;
}
}
}
1 change: 0 additions & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ protected function createRootProblems(): ?array
'service.host',
'service.host.state'
])
->setResultSetClass(VolatileStateResults::class)
->orderBy([
'host.state.severity',
'host.state.last_state_change',
Expand Down

0 comments on commit b52c219

Please sign in to comment.