[icinga-checkins] icinga.org: icinga-web/master: * Fixed worst to performance problems ever

git at icinga.org git at icinga.org
Thu Dec 1 11:43:59 CET 2011


Module: icinga-web
Branch: master
Commit: 53518234671ae57308cfc380b9062c85db6e0a49
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=53518234671ae57308cfc380b9062c85db6e0a49

Author: Marius Hein <marius.hein at netways.de>
Date:   Thu Dec  1 11:41:40 2011 +0100

* Fixed worst to performance problems ever

Conflicts:

	app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-cv.xml

---

 app/modules/AppKit/lib/database/models/NsmRole.php |   64 +++++++++++--------
 app/modules/AppKit/lib/database/models/NsmUser.php |   65 +++++++++++---------
 .../to/icinga-tactical-overview-template-cv.xml    |    6 +-
 3 files changed, 79 insertions(+), 56 deletions(-)

diff --git a/app/modules/AppKit/lib/database/models/NsmRole.php b/app/modules/AppKit/lib/database/models/NsmRole.php
index dad0264..5111ba0 100644
--- a/app/modules/AppKit/lib/database/models/NsmRole.php
+++ b/app/modules/AppKit/lib/database/models/NsmRole.php
@@ -9,6 +9,12 @@ class NsmRole extends BaseNsmRole {
     private $children = null;
     private $context = null;
     private $storage = null;
+    
+    /**
+    * Reduce database query overhead
+    * @var array
+    */
+    private static $targetValuesCache = array();
 
     public function setUp() {
 
@@ -208,36 +214,42 @@ class NsmRole extends BaseNsmRole {
     }
 
     public function getTargetValuesArray() {
-        $tc = Doctrine_Query::create()
-              ->select('t.target_name, t.target_id')
-              ->from('NsmTarget t')
-              ->innerJoin('t.NsmPrincipalTarget pt')
-              ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
-              ->execute();
-
-        $out = array();
-
-        foreach($tc as $t) {
-            $out[ $t->target_name ] = array();
-
-            $ptc = Doctrine_Query::create()
-                   ->from('NsmPrincipalTarget pt')
-                   ->innerJoin('pt.NsmTargetValue tv')
-                   ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
-                   ->andWhere('pt.pt_target_id=?', array($t->target_id))
-                   ->execute();
-
-            foreach($ptc as $pt) {
-                $tmp = array();
-                foreach($pt->NsmTargetValue as $tv) {
-                    $tmp[ $tv->tv_key ] = $tv->tv_val;
+        
+        if (count(self::$targetValuesCache) == 0) {
+            $tc = Doctrine_Query::create()
+                  ->select('t.target_name, t.target_id')
+                  ->from('NsmTarget t')
+                  ->innerJoin('t.NsmPrincipalTarget pt')
+                  ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
+                  ->execute();
+    
+            $out = array();
+    
+            foreach($tc as $t) {
+                $out[ $t->target_name ] = array();
+    
+                $ptc = Doctrine_Query::create()
+                       ->from('NsmPrincipalTarget pt')
+                       ->innerJoin('pt.NsmTargetValue tv')
+                       ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
+                       ->andWhere('pt.pt_target_id=?', array($t->target_id))
+                       ->execute();
+    
+                foreach($ptc as $pt) {
+                    $tmp = array();
+                    foreach($pt->NsmTargetValue as $tv) {
+                        $tmp[ $tv->tv_key ] = $tv->tv_val;
+                    }
+    
+                    $out[ $t->target_name ][] = $tmp;
                 }
-
-                $out[ $t->target_name ][] = $tmp;
             }
+            
+            self::$targetValuesCache =& $out;
+        
         }
         
 
-        return $out;
+        return self::$targetValuesCache;
     }
 }
diff --git a/app/modules/AppKit/lib/database/models/NsmUser.php b/app/modules/AppKit/lib/database/models/NsmUser.php
index 68ee64d..65c660b 100644
--- a/app/modules/AppKit/lib/database/models/NsmUser.php
+++ b/app/modules/AppKit/lib/database/models/NsmUser.php
@@ -8,6 +8,12 @@ class NsmUser extends BaseNsmUser {
     const HASH_ALGO = 'sha256';
 
     private static $prefCache = array();
+    
+    /**
+     * Reduce database query overhead
+     * @var array
+     */
+    private static $targetValuesCache = array();
 
     /**
      * @var Doctrine_Collection
@@ -489,36 +495,39 @@ class NsmUser extends BaseNsmUser {
     }
 
     public function getTargetValuesArray() {
-        $tc = Doctrine_Query::create()
-              ->select('t.target_name, t.target_id')
-              ->from('NsmTarget t')
-              ->innerJoin('t.NsmPrincipalTarget pt')
-              ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
-              ->execute();
-
-        $out = array();
-
-        foreach($tc as $t) {
-            $out[ $t->target_name ] = array();
-
-            $ptc = Doctrine_Query::create()
-                   ->from('NsmPrincipalTarget pt')
-                   ->innerJoin('pt.NsmTargetValue tv')
-                   ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
-                   ->andWhere('pt.pt_target_id=?', array($t->target_id))
-                   ->execute();
-
-            foreach($ptc as $pt) {
-                $tmp = array();
-                foreach($pt->NsmTargetValue as $tv) {
-                    $tmp[ $tv->tv_key ] = $tv->tv_val;
+        if (count(self::$targetValuesCache) == 0) {
+            $tc = Doctrine_Query::create()
+                  ->select('t.target_name, t.target_id')
+                  ->from('NsmTarget t')
+                  ->innerJoin('t.NsmPrincipalTarget pt')
+                  ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
+                  ->execute();
+    
+            $out = array();
+    
+            foreach($tc as $t) {
+                $out[ $t->target_name ] = array();
+    
+                $ptc = Doctrine_Query::create()
+                       ->from('NsmPrincipalTarget pt')
+                       ->innerJoin('pt.NsmTargetValue tv')
+                       ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList())
+                       ->andWhere('pt.pt_target_id=?', array($t->target_id))
+                       ->execute();
+    
+                foreach($ptc as $pt) {
+                    $tmp = array();
+                    foreach($pt->NsmTargetValue as $tv) {
+                        $tmp[ $tv->tv_key ] = $tv->tv_val;
+                    }
+    
+                    $out[ $t->target_name ][] = $tmp;
                 }
-
-                $out[ $t->target_name ][] = $tmp;
+                
+                self::$targetValuesCache =& $out;
             }
+        
         }
-    
-
-        return $out;
+        return self::$targetValuesCache;
     }
 }
diff --git a/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-cv.xml b/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-cv.xml
index d5a63e5..33149ec 100644
--- a/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-cv.xml
+++ b/app/modules/Cronks/data/xml/to/icinga-tactical-overview-template-cv.xml
@@ -32,12 +32,14 @@
                     $records = IcingaDoctrine_Query::create()
                     ->from('IcingaCustomvariables c')
                     ->distinct(true)
-                    ->select('c.customvariable_id, c.varname, c.varvalue')
+                    ->select('c.varname, c.varvalue')
                     ->orderBy('c.varname ASC')
-                    ->andWhereNotIn('c.varname', array('PASSWORD'))
+                    ->appendCustomvarFilter()
+                    ->disableAutoIdentifierFields(true)
                     ->execute();
                     
                     foreach ($records as $record) {
+                        // echo $record->varname . ":" . $record->varvalue . "<br />";
                         echo $t->renderSub('icinga-tactical-overview-groupstat', 'customvariable', array(
                             'CUSTOMVARIABLE_NAME' => $record->varname,
                             'CUSTOMVARIABLE_VALUE' => $record->varvalue





More information about the icinga-checkins mailing list