Cache count in MonitoringBadgeNavigationItemRenderer
This commit is contained in:
parent
0665ca387b
commit
4f77cce7a9
|
@ -22,6 +22,13 @@ use Icinga\Web\Navigation\Renderer\SummaryNavigationItemRenderer;
|
||||||
*/
|
*/
|
||||||
class MonitoringBadgeNavigationItemRenderer extends SummaryNavigationItemRenderer
|
class MonitoringBadgeNavigationItemRenderer extends SummaryNavigationItemRenderer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Cached count
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the responses for all executed summaries
|
* Caches the responses for all executed summaries
|
||||||
*
|
*
|
||||||
|
@ -164,20 +171,24 @@ class MonitoringBadgeNavigationItemRenderer extends SummaryNavigationItemRendere
|
||||||
*/
|
*/
|
||||||
public function getCount()
|
public function getCount()
|
||||||
{
|
{
|
||||||
try {
|
if ($this->count === null) {
|
||||||
$summary = self::summary($this->getDataView());
|
try {
|
||||||
} catch (Exception $_) {
|
$summary = self::summary($this->getDataView());
|
||||||
return 0;
|
} catch (Exception $_) {
|
||||||
}
|
$this->count = 0;
|
||||||
|
|
||||||
$count = 0;
|
|
||||||
foreach ($this->getColumns() as $column => $title) {
|
|
||||||
if (isset($summary->$column) && $summary->$column > 0) {
|
|
||||||
$this->titles[] = sprintf($title, $summary->$column);
|
|
||||||
$count += $summary->$column;
|
|
||||||
}
|
}
|
||||||
|
$count = 0;
|
||||||
|
$titles = array();
|
||||||
|
foreach ($this->getColumns() as $column => $title) {
|
||||||
|
if (isset($summary->$column) && $summary->$column > 0) {
|
||||||
|
$titles[] = sprintf($title, $summary->$column);
|
||||||
|
$count += $summary->$column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->count = $count;
|
||||||
|
$this->title = implode('. ', $titles);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count;
|
return $this->count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue