From 28790d254b0ef8074b344b04c3b805aeb28cee3a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 27 Jul 2017 11:29:57 +0200 Subject: [PATCH] Remove caching form the MonitoringBadgeNavigationItemRenderer Caching will be no longer necessary because we will replace the queries used to fetch the problem badges. --- .../MonitoringBadgeNavigationItemRenderer.php | 56 ++++--------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php b/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php index 842ce344f..683893b22 100644 --- a/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php +++ b/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php @@ -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; }