Remove caching form the MonitoringBadgeNavigationItemRenderer

Caching will be no longer necessary because we will replace the queries used to fetch the problem badges.
This commit is contained in:
Eric Lippmann 2017-07-27 11:29:57 +02:00
parent c0d359fbbd
commit 28790d254b
1 changed files with 12 additions and 44 deletions

View File

@ -11,14 +11,11 @@ use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
/**
* Render generic dataView columns as badges in MenuItems
*
* Renders numeric data view column values into menu item badges, fully configurable
* and with a caching mechanism to prevent needless requests to the same data view.
* Render generic DataView columns as badges in menu items
*
* It is possible to configure the class of the rendered badge as option 'class', the
* column to fetch using the option 'column' and the dataView from which the columns
* will be fetched using the option 'dataView'.
* columns to fetch using the option 'columns' and the DataView from which the columns
* will be fetched using the option 'dataview'.
*/
class MonitoringBadgeNavigationItemRenderer extends BadgeNavigationItemRenderer
{
@ -104,29 +101,6 @@ class MonitoringBadgeNavigationItemRenderer extends BadgeNavigationItemRenderer
return $this->columns;
}
/**
* {@inheritdoc}
*/
public function init()
{
// clear the outdated summary cache, since new columns are being added. Optimally all menu item are constructed
// before any rendering is going on to avoid trashing too man old requests
if (isset(self::$summaries[$this->dataView])) {
unset(self::$summaries[$this->dataView]);
}
// add the new columns to this view
if (! isset(self::$dataViews[$this->dataView])) {
self::$dataViews[$this->dataView] = array();
}
foreach ($this->columns as $column => $title) {
if (! array_search($column, self::$dataViews[$this->dataView])) {
self::$dataViews[$this->dataView][] = $column;
}
}
}
/**
* Apply a restriction on the given data view
*
@ -146,24 +120,18 @@ class MonitoringBadgeNavigationItemRenderer extends BadgeNavigationItemRenderer
}
/**
* Fetch the dataview from the database or access cache
*
* @param string $view
* Fetch the dataview from the database
*
* @return object
*/
protected static function summary($view)
protected function fetchDataView()
{
if (! isset(self::$summaries[$view])) {
$summary = MonitoringBackend::instance()->select()->from(
$view,
self::$dataViews[$view]
);
static::applyRestriction('monitoring/filter/objects', $summary);
self::$summaries[$view] = $summary->fetchRow();
}
return self::$summaries[$view];
$summary = MonitoringBackend::instance()->select()->from(
$this->getDataView(),
array_keys($this->getColumns())
);
static::applyRestriction('monitoring/filter/objects', $summary);
return $summary->fetchRow();
}
/**
@ -173,7 +141,7 @@ class MonitoringBadgeNavigationItemRenderer extends BadgeNavigationItemRenderer
{
if ($this->count === null) {
try {
$summary = self::summary($this->getDataView());
$summary = $this->fetchDataView();
} catch (Exception $_) {
$this->count = 0;
}