Skip to content

Commit

Permalink
Don't require relation state in state summarie queries
Browse files Browse the repository at this point in the history
Lets the models add the relation on their own, using
`utilize()` as the relation is only needed inside
expressions.
  • Loading branch information
nilmerg committed May 20, 2022
1 parent 12624b3 commit 854151f
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions application/controllers/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function indexAction()
$db = $this->getDb();

$instance = Instance::on($db)->with('endpoint');
$hoststateSummary = HoststateSummary::on($db)->with('state');
$servicestateSummary = ServicestateSummary::on($db)->with('state');
$hoststateSummary = HoststateSummary::on($db);
$servicestateSummary = ServicestateSummary::on($db);

$this->applyRestrictions($hoststateSummary);
$this->applyRestrictions($servicestateSummary);
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function init()

public function indexAction()
{
$serviceSummary = ServicestateSummary::on($this->getDb())->with('state');
$serviceSummary = ServicestateSummary::on($this->getDb());
$serviceSummary->filter(Filter::equal('service.host_id', $this->host->id));

$this->applyRestrictions($serviceSummary);
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/HostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function indexAction()

$summary = null;
if (! $compact) {
$summary = HoststateSummary::on($db)->with('state');
$summary = HoststateSummary::on($db);
}

$limitControl = $this->createLimitControl();
Expand Down Expand Up @@ -226,7 +226,7 @@ protected function getCommandTargetsUrl(): Url

protected function getFeatureStatus()
{
$summary = HoststateSummary::on($this->getDb())->with(['state']);
$summary = HoststateSummary::on($this->getDb());
$this->filter($summary);

return new FeatureStatus('host', $summary->first());
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/ServicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function indexAction()

$summary = null;
if (! $compact) {
$summary = ServicestateSummary::on($db)->with('state');
$summary = ServicestateSummary::on($db);
}

$limitControl = $this->createLimitControl();
Expand Down Expand Up @@ -347,7 +347,7 @@ protected function getCommandTargetsUrl(): Url

protected function getFeatureStatus()
{
$summary = ServicestateSummary::on($this->getDb())->with(['state']);
$summary = ServicestateSummary::on($this->getDb());
$this->filter($summary);

return new FeatureStatus('service', $summary->first());
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/TacticalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function indexAction()

$db = $this->getDb();

$hoststateSummary = HoststateSummary::on($db)->with('state');
$servicestateSummary = ServicestateSummary::on($db)->with(['state']);
$hoststateSummary = HoststateSummary::on($db);
$servicestateSummary = ServicestateSummary::on($db);

$this->handleSearchRequest($servicestateSummary);

Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Model/HoststateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static function on(Connection $db)
/** @var static $m */
$m = $q->getModel();
$q->columns($m->getSummaryColumns());
$q->utilize('state');

return $q;
}
Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Model/ServicestateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static function on(Connection $db)
/** @var static $m */
$m = $q->getModel();
$q->columns($m->getSummaryColumns());
$q->utilize('state');

return $q;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HostProblemsBadge extends ProblemsBadge

protected function fetchProblemsCount()
{
$summary = HoststateSummary::on($this->getDb())->with('state');
$summary = HoststateSummary::on($this->getDb());
$this->applyRestrictions($summary);
$count = (int) $summary->first()->hosts_down_unhandled;
if ($count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ServiceProblemsBadge extends ProblemsBadge

protected function fetchProblemsCount()
{
$summary = ServicestateSummary::on($this->getDb())->with('state');
$summary = ServicestateSummary::on($this->getDb());
$this->applyRestrictions($summary);
$count = (int) $summary->first()->services_critical_unhandled;
if ($count) {
Expand Down

0 comments on commit 854151f

Please sign in to comment.