[icinga-checkins] icinga.org: icinga-web/master: Session: Do not write session on every request

git at icinga.org git at icinga.org
Tue Nov 18 17:10:10 CET 2014


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Oct 28 15:29:31 2014 +0100

Session: Do not write session on every request

This speed up the gui by at least 20%.

Refs #7718

---

 .../storage/AppKitDoctrineSessionStorage.class.php |   24 ++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php b/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php
index e9f40a7..49286e1 100644
--- a/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php
+++ b/app/modules/AppKit/lib/storage/AppKitDoctrineSessionStorage.class.php
@@ -170,11 +170,31 @@ class AppKitDoctrineSessionStorage extends AgaviSessionStorage {
      * @param mixed $data
      */
     public function sessionWrite($id, &$data) {
-        AppKitLogger::verbose("Writing new session information (checksum=%s)",md5($data));
+        $max = ini_get('session.gc_maxlifetime');
+        $update = false;
+
+        if (! $max) {
+            $max = 1440;
+        }
+
+        $date = new DateTime($this->NsmSession->session_modified);
+        $m = null;
+
+        if ((time() - $date->getTimestamp()) >= $max) {
+            $update = true;
+        }
+
+        if (! $update && $this->NsmSession->session_checksum === ($m = md5($data))) {
+            return;
+        }
+
+        AppKitLogger::verbose("Writing new session information (checksum=%s)", $m);
+
         $this->NsmSession->session_data = $data;
-        $this->NsmSession->session_checksum = md5($data);
+        $this->NsmSession->session_checksum = $m;
         $this->NsmSession->session_modified = date('Y-m-d H:i:s');
         $this->NsmSession->save();
+
         AppKitLogger::verbose("Writing new session information successful");
     }
 



More information about the icinga-checkins mailing list