[icinga-checkins] icinga.org: icingaweb2/master: Cache count in MonitoringBadgeNavigationItemRenderer

git at icinga.org git at icinga.org
Thu Dec 8 10:40:33 CET 2016


Module: icingaweb2
Branch: master
Commit: 4f77cce7a9e0abd54852ad96fba8c9ba6656d8ff
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=4f77cce7a9e0abd54852ad96fba8c9ba6656d8ff

Author: Eric Lippmann <eric.lippmann at icinga.com>
Date:   Tue Dec  6 14:39:22 2016 +0100

Cache count in MonitoringBadgeNavigationItemRenderer

---

 .../MonitoringBadgeNavigationItemRenderer.php      |   35 +++++++++++++-------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php b/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php
index 3f17a5e..f050ca4 100644
--- a/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php
+++ b/modules/monitoring/library/Monitoring/Web/Navigation/Renderer/MonitoringBadgeNavigationItemRenderer.php
@@ -23,6 +23,13 @@ use Icinga\Web\Navigation\Renderer\SummaryNavigationItemRenderer;
 class MonitoringBadgeNavigationItemRenderer extends SummaryNavigationItemRenderer
 {
     /**
+     * Cached count
+     *
+     * @var int
+     */
+    protected $count;
+
+    /**
      * Caches the responses for all executed summaries
      *
      * @var array
@@ -164,20 +171,24 @@ class MonitoringBadgeNavigationItemRenderer extends SummaryNavigationItemRendere
      */
     public function getCount()
     {
-        try {
-            $summary = self::summary($this->getDataView());
-        } catch (Exception $_) {
-            return 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;
+        if ($this->count === null) {
+            try {
+                $summary = self::summary($this->getDataView());
+            } catch (Exception $_) {
+                $this->count = 0;
+            }
+            $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;
     }
 }



More information about the icinga-checkins mailing list