Some speed improvements again.
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Fri, 16 Nov 2007 09:25:19 +0000 (09:25 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:58 +0000 (00:35 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@306 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/nntp.inc.php
banana/nntpcore.inc.php
banana/tree.inc.php

index 26cb3a5..1311029 100644 (file)
@@ -673,26 +673,7 @@ class Banana
     {
         Banana::load('spool');
         if (!Banana::$spool || Banana::$spool->group != $group) {
-            $clean = false;
-            if (php_sapi_name() != 'cli') {
-                if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
-                    Banana::$spool = unserialize($_SESSION['banana_spool']);
-                    unset($_SESSION['banana_spool']);
-                    $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']);
-                } else {
-                    unset($_SESSION['banana_message']);
-                    unset($_SESSION['banana_artid']);
-                    unset($_SESSION['banana_showhdr']);
-                }
-            }
-            BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup'] || $clean);
-            if (php_sapi_name() != 'cli') {
-                $_SESSION['banana_group'] = $group;
-                if (!Banana::$profile['display']) {
-                    $_SESSION['banana_spool'] = serialize(Banana::$spool);
-                    $_SESSION['banana_lastnews'] = Banana::$profile['lastnews'];
-                }
-            }
+            BananaSpool::getSpool($group, Banana::$profile['lastnews'], Banana::$profile['autoup']);
             Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
         }
         return true;
index 6245803..a9b7be0 100644 (file)
@@ -76,10 +76,10 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
                     if (!is_utf8($desc)) {
                         $desc = utf8_encode($desc);
                     }
-                    $this->boxes[$group] = array('desc' => $desc);           
+                    $this->boxes[$group] = array('desc' => $desc);
                 } else {
                     $this->boxes[$group] = array('desc' => null);
-                }    
+                }
             }
             ksort($this->boxes);
         }
index 4b8e9c0..3029c08 100644 (file)
@@ -100,9 +100,10 @@ class BananaNNTPCore
     /** get a line from server
      * @return STRING 
      */
-    private function getLine()
+    private function &getLine()
     {
-        return rtrim(@fgets($this->ns, 1200), "\r\n");
+        $data = rtrim(@fgets($this->ns, 1200), "\r\n");
+        return $data;
     }
 
     /** fetch data (and on delimitor)
@@ -111,11 +112,13 @@ class BananaNNTPCore
     private function &fetchResult()
     {
         $array = Array();
-        while (($result = $this->getLine()) != '.') {
-            $array[] = $result;
+        while (($result =& $this->getLine()) != '.') {
+            $array[] =& $result;
         }
         if ($this->debug && $this->bt) {
-            $this->bt[count($this->bt) - 1]['response'] = count($array);
+            $trace =& $this->bt[count($this->bt) - 1];
+            $trace['response'] = count($array);
+            $trace['time']     = microtime(true) - $trace['start'];
         }
         return $array;
     }
@@ -131,7 +134,7 @@ class BananaNNTPCore
         }
         if ($this->debug) {
             $db_line = preg_replace('/PASS .*/', 'PASS *******', $line);
-            $this->bt[] = array('action' => $db_line, 'time' => microtime(true));
+            $this->bt[] = array('action' => $db_line, 'start' => microtime(true));
         }
         return @fputs($this->ns, $line, strlen($line));
     }
@@ -172,7 +175,7 @@ class BananaNNTPCore
         $this->lastresulttext = substr($result, 4);
         if ($this->debug && $this->bt) {
             $trace =& $this->bt[count($this->bt) - 1];
-            $trace['time']     = microtime(true) - $trace['time'];
+            $trace['time']     = microtime(true) - $trace['start'];
             $trace['code']     = $this->lastresultcode;
             $trace['message']  = $this->lastresulttext;
             $trace['response'] = 0;
index 09fe261..e19e6ab 100644 (file)
@@ -95,19 +95,21 @@ class BananaTree
         if (!is_null($this->displaid) || is_null($this->data)) {
             return $this->displaid;
         }
-        static $t_e, $u_h, $u_ht, $u_vt, $u_l, $u_f, $r_h, $r_ht, $r_vt, $r_l, $r_f;
+        static $t_e, $tree;
+        //$u_h, $u_ht, $u_vt, $u_l, $u_f, $r_h, $r_ht, $r_vt, $r_l, $r_f;
         if (!isset($t_e)) {
+            $tree  = array();
             $t_e   = Banana::$page->makeImg(Array('img' => 'e',  'alt' => ' ', 'height' => 18, 'width' => 14));
-            $u_h   = Banana::$page->makeImg(Array('img' => 'h2', 'alt' => '-', 'height' => 18,  'width' => 14));
-            $u_ht  = Banana::$page->makeImg(Array('img' => 'T2', 'alt' => '+', 'height' => 18, 'width' => 14));
-            $u_vt  = Banana::$page->makeImg(Array('img' => 't2', 'alt' => '`', 'height' => 18, 'width' => 14));
-            $u_l   = Banana::$page->makeImg(Array('img' => 'l2', 'alt' => '|', 'height' => 18, 'width' => 14));
-            $u_f   = Banana::$page->makeImg(Array('img' => 'f2', 'alt' => 't', 'height' => 18, 'width' => 14));
-            $r_h   = Banana::$page->makeImg(Array('img' => 'h2r', 'alt' => '-', 'height' => 18, 'width' => 14));
-            $r_ht  = Banana::$page->makeImg(Array('img' => 'T2r', 'alt' => '+', 'height' => 18, 'width' => 14));
-            $r_vt  = Banana::$page->makeImg(Array('img' => 't2r', 'alt' => '`', 'height' => 18, 'width' => 14));
-            $r_l   = Banana::$page->makeImg(Array('img' => 'l2r', 'alt' => '|', 'height' => 18, 'width' => 14));
-            $r_f   = Banana::$page->makeImg(Array('img' => 'f2r', 'alt' => 't', 'height' => 18, 'width' => 14));
+            $tree['+'] = array(Banana::$page->makeImg(Array('img' => 'T2', 'alt' => '-', 'height' => 18,  'width' => 14)),
+                               Banana::$page->makeImg(Array('img' => 'T2r', 'alt' => '+', 'height' => 18, 'width' => 14)));
+            $tree['-'] = array(Banana::$page->makeImg(Array('img' => 'h2', 'alt' => '-', 'height' => 18,  'width' => 14)),
+                               Banana::$page->makeImg(Array('img' => 'h2r', 'alt' => '-', 'height' => 18, 'width' => 14)));
+            $tree['|'] = array(Banana::$page->makeImg(Array('img' => 'l2', 'alt' => '|', 'height' => 18, 'width' => 14)),
+                               Banana::$page->makeImg(Array('img' => 'l2r', 'alt' => '|', 'height' => 18, 'width' => 14)));
+            $tree['`'] = array(Banana::$page->makeImg(Array('img' => 't2', 'alt' => '`', 'height' => 18, 'width' => 14)),
+                               Banana::$page->makeImg(Array('img' => 't2r', 'alt' => '`', 'height' => 18, 'width' => 14)));
+            $tree['t'] = array(Banana::$page->makeImg(Array('img' => 'f2', 'alt' => 't', 'height' => 18, 'width' => 14)),
+                               Banana::$page->makeImg(Array('img' => 'f2r', 'alt' => 't', 'height' => 18, 'width' => 14)));
         }
         $text = '<div class="tree">';
         foreach ($this->data as &$line) {
@@ -117,18 +119,11 @@ class BananaTree
                     $text .= $t_e;
                 } else if (is_array($item)) {
                     $head =& Banana::$spool->overview[$item[1]];
-                    switch ($item[0]) {
-                      case '+': $text .= $head->isread ? $r_ht : $u_ht; break;
-                      case '-': $text .= $head->isread ? $r_h : $u_h; break;
-                      case '|': $text .= $head->isread ? $r_l : $u_l; break;
-                      case '`': $text .= $head->isread ? $r_vt : $u_vt; break;
-                      case 't': $text .= $head->isread ? $r_f : $u_f; break;
-                    }
+                    $text .= $tree[$item[0]][$head->isread ? 1 : 0];
                 } else {
                     $head =& Banana::$spool->overview[$item];
-                    $text .= '<span style="background-color:' . $head->color . '; text-decoration: none"'
-                          .       ' title="' .  $this->title[$item] . '">'
-                          .  '<input type="radio" name="banana_tree" value="' . $head->id . '"';
+                    $text .= '<span style="background-color: ' . $head->color . '; text-decoration: none" title="'
+                          .  $this->title[$item] . '"><input type="radio" name="banana_tree" value="' . $head->id . '"';
                     if (Banana::$msgshow_javascript) {
                         $text .= ' onchange="window.location=\'' . $this->urls[$item] . '\'"';
                     } else {