[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Added session-caching for principals

git at icinga.org git at icinga.org
Fri Aug 12 12:44:50 CEST 2011


Module: icinga-web
Branch: jmosshammer/default
Commit: 83135a1510309545344214f36c7015a39706d348
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=83135a1510309545344214f36c7015a39706d348

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Fri Aug 12 12:44:23 2011 +0200

* Added session-caching for principals

---

 app/modules/AppKit/lib/database/models/NsmRole.php |   38 +++++++++++++++-
 app/modules/AppKit/lib/database/models/NsmUser.php |   48 +++++++++++++++++---
 2 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/app/modules/AppKit/lib/database/models/NsmRole.php b/app/modules/AppKit/lib/database/models/NsmRole.php
index 703a240..9b146e1 100644
--- a/app/modules/AppKit/lib/database/models/NsmRole.php
+++ b/app/modules/AppKit/lib/database/models/NsmRole.php
@@ -7,6 +7,8 @@ class NsmRole extends BaseNsmRole {
     private $principals_list = null;
     private $principals = null;
     private $children = null;
+    private $context = null;
+    private $storage = null;
 
     public function setUp() {
 
@@ -25,6 +27,19 @@ class NsmRole extends BaseNsmRole {
 
     }
 
+    public function getContext() {
+        if(!$this->context)
+            $this->context = AgaviContext::getInstance();
+        return $this->context;
+    }
+
+    public function getStorage() {
+        if(!$this->storage)
+            $this->storage = $this->getContext()->getStorage();
+        return $this->storage;
+    }
+
+
     public function hasParent() {
         if ($this->get('role_parent')) {
             return true;
@@ -174,10 +189,21 @@ class NsmRole extends BaseNsmRole {
      * @return Doctrine_Collection
      */
     public function getTargetValues($target_name) {
+        if($this->getStorage()->read("target_".$target_name."_role")) {
+            $targets = unserialize($this->getStorage()->read("target_".$target_name."_role"));
+            if($targets)
+                return $targets;
+        }
+        $this->getStorage()->write("target_".$target_name."_role",serialize($result));
         return $this->getTargetValuesQuery($target_name)->execute();
     }
 
     public function getTargetValue($target_name, $value_name) {
+        if($this->getStorage()->read("target_".$target_name."_".$value_name."_role")) {
+            $targets = unserialize($this->getStorage()->read("target_".$target_name."_".$value_name."_role"));
+            if($targets)
+                return $targets;
+        }
         $q = $this->getTargetValuesQuery($target_name);
         $q->select('tv.tv_val');
         $q->andWhere('tv.tv_key=?', array($value_name));
@@ -187,10 +213,19 @@ class NsmRole extends BaseNsmRole {
         foreach($res as $r) {
             $out[] = $r->tv_val;
         }
+        
+        $this->getStorage()->write("target_".$target_name."_".$value_name."_role",serialize($out));
         return $out;
     }
 
     public function getTargetValuesArray() {
+        if($this->getStorage()->read("targetValuesArray_role")) {
+            $targets = unserialize($this->getStorage()->read("targetValuesArray_role"));
+            if($targets)
+                return $targets;
+        }
+
+
         $tc = Doctrine_Query::create()
               ->select('t.target_name, t.target_id')
               ->from('NsmTarget t')
@@ -219,7 +254,8 @@ class NsmRole extends BaseNsmRole {
                 $out[ $t->target_name ][] = $tmp;
             }
         }
-
+        
+        $this->getStorage()->write("targetValuesArray_role",serialize($out));
         return $out;
     }
 }
diff --git a/app/modules/AppKit/lib/database/models/NsmUser.php b/app/modules/AppKit/lib/database/models/NsmUser.php
index d273a1d..d41f6fd 100644
--- a/app/modules/AppKit/lib/database/models/NsmUser.php
+++ b/app/modules/AppKit/lib/database/models/NsmUser.php
@@ -7,6 +7,8 @@ class NsmUser extends BaseNsmUser {
 
     const HASH_ALGO = 'sha256';
 
+    private static $prefCache = array();
+
     /**
      *
      * @var Doctrine_Collection
@@ -18,7 +20,8 @@ class NsmUser extends BaseNsmUser {
      * @var array
      */
     private $principals_list	= null;
-
+    private $context = null;
+    private $storage = null;
     /**
      * (non-PHPdoc)
      * @see lib/appkit/database/models/generated/BaseNsmUser#setTableDefinition()
@@ -44,8 +47,20 @@ class NsmUser extends BaseNsmUser {
                      ));
     }
 
-    public function setUp() {
+    public function getContext() {
+        if(!$this->context)
+            $this->context = AgaviContext::getInstance();
+        return $this->context;
+    }
 
+    public function getStorage() {
+        if(!$this->storage)
+            $this->storage = $this->getContext()->getStorage();
+        return $this->storage;
+    }
+
+    public function setUp() {
+        
         parent::setUp();
 
         $this->hasMany('NsmRole', array('local'		=> 'usro_user_id',
@@ -419,10 +434,23 @@ class NsmUser extends BaseNsmUser {
      * @return Doctrine_Collection
      */
     public function getTargetValues($target_name) {
-        return $this->getTargetValuesQuery($target_name)->execute();
+        if($this->getStorage()->read("target_".$target_name)) {
+            $targets = unserialize($this->getStorage()->read("target_".$target_name));
+            if($targets)
+                return $targets;
+        }
+        $result =  $this->getTargetValuesQuery($target_name)->execute(); 
+        $this->getStorage()->write("target_".$target_name,serialize($result));
+        
+        return $result;
     }
 
     public function getTargetValue($target_name, $value_name) {
+        if($this->getStorage()->read("target_".$target_name."_".$value_name)) {
+            $targets = unserialize($this->getStorage()->read("target_".$target_name."_".$value_name));
+            if($targets)
+                return $targets;
+        }
         $q = $this->getTargetValuesQuery($target_name);
         $q->select('tv.tv_val');
         $q->andWhere('tv.tv_key=?', array($value_name));
@@ -432,10 +460,17 @@ class NsmUser extends BaseNsmUser {
         foreach($res as $r) {
             $out[] = $r->tv_val;
         }
-        return $out;
+        $this->getStorage()->write("target_".$target_name."_".$value_name,serialize($out));
+        return $targets;
     }
 
     public function getTargetValuesArray() {
+        if($this->getStorage()->read("targetValuesArray")) {
+            $targets = unserialize($this->getStorage()->read("targetValuesArray"));
+            if($targets)
+                return $targets;
+        }
+
         $tc = Doctrine_Query::create()
               ->select('t.target_name, t.target_id')
               ->from('NsmTarget t')
@@ -464,7 +499,8 @@ class NsmUser extends BaseNsmUser {
                 $out[ $t->target_name ][] = $tmp;
             }
         }
-
+    
+        $this->getStorage()->write("targetValuesArray",serialize($out));
         return $out;
     }
-}
\ No newline at end of file
+}





More information about the icinga-checkins mailing list