Speed-up
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Sun, 6 May 2007 13:29:38 +0000 (13:29 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:41 +0000 (00:35 +0100)
 banana.inc.php.in |   26 +++++++++++++++-----------
 mbox.inc.php      |   48 +++++++++++++++++++++++++-----------------------
 message.inc.php   |   11 +++++++++--
 mimepart.inc.php  |    4 ++--
 nntp.inc.php      |    3 ++-
 spool.inc.php     |    6 +++---
 6 files changed, 56 insertions(+), 42 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@248 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/mbox.inc.php
banana/message.inc.php
banana/mimepart.inc.php
banana/nntp.inc.php
banana/spool.inc.php

index 0698454..df16d8b 100644 (file)
@@ -666,19 +666,23 @@ class Banana
         Banana::load('spool');
         if (!Banana::$spool || Banana::$spool->group != $group) {
             $clean = false;
-            if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
-                Banana::$spool = unserialize($_SESSION['banana_spool']);
-                $clean = @(Banana::$profile['lastnews'] != $_SESSION['banana_lastnews']);
-            } else {
-                unset($_SESSION['banana_message']);
-                unset($_SESSION['banana_artid']);
-                unset($_SESSION['banana_showhdr']);
+            if (php_sapi_name() != 'cli') {
+                if ($group == @$_SESSION['banana_group'] && isset($_SESSION['banana_spool'])) {
+                    Banana::$spool = unserialize($_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);
-            $_SESSION['banana_group'] = $group;
-            if (!Banana::$profile['display']) {
-                $_SESSION['banana_spool'] = serialize(Banana::$spool);
-                $_SESSION['banana_lastnews'] = Banana::$profile['lastnews'];
+            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'];
+                }
             }
             Banana::$spool->setMode(Banana::$profile['display'] ? Banana::SPOOL_UNREAD : Banana::SPOOL_ALL);
         }
index 01c329e..c0fb8ae 100644 (file)
@@ -106,7 +106,7 @@ class BananaMBox implements BananaProtocoleInterface
     {
         $options = array();
         if (@filesize($this->getFileName()) == Banana::$spool->storage['size']) { 
-            return max(Banana::$spool->ids); 
+            return max(Banana::$spool->ids) + 1
         } 
         $this->getMBoxPosition($options);
         $val =& $this->callHelper('-c', $options);
@@ -139,31 +139,33 @@ class BananaMBox implements BananaProtocoleInterface
             return $headers;
         }
         $headers = array();
-        while ($lines) {
-            $id = array_shift($lines);
-            if ($id === '') {
-                continue;
-            }
-            $offset = array_shift($lines);
-            if ($offset === '') {
-                continue;
-            }
-            $id     = intval($id);
-            $headers[$id] = array('beginning' => intval($offset));
-            while (true) {
-                $hname = array_shift($lines);
-                if ($hname === '') {
-                    break;
-                }
-                $hval  = array_shift($lines);
-                if ($hname == 'date') {
-                    $headers[$id][$hname] = @strtotime($hval);
-                } else {
-                    $headers[$id][$hname] = $hval;
+        $in_message = false;
+        $get_pos    = true;
+        $hname      = null;
+        foreach ($lines as $key=>&$line) {
+            if (!$in_message) {
+                if (!empty($line)) {
+                    $id = intval($line);
+                    $in_message = true;
+                    $get_pos    = true;
                 }
+            } elseif ($get_pos) {
+                $headers[$id] = array('beginning' => intval($line));
+                $get_pos = false;
+            } elseif (empty($line) && empty($hname)) {
+                $in_message = false;
+            } elseif (empty($hname)) {
+                $hname = $line;
+            } elseif ($hname == 'date') {
+                $headers[$id][$hname] = @strtotime($line);
+                $hname = null;
+            } else {
+                BananaMimePart::decodeHeader($line, $hname);
+                $headers[$id][$hname] = $line;
+                $hname = null;
             }
+            unset($lines[$key]);
         }
-        array_walk_recursive($headers, array('BananaMimePart', 'decodeHeader'));
         return $headers;
     }
 
index 8acd4a3..dcb9d02 100644 (file)
@@ -229,8 +229,15 @@ final class BananaMessage extends BananaMimePart
     static public function formatReferences(array &$refs)
     {
         if (isset($refs['references'])) {
-            $text = str_replace('><', '> <', $refs['references']);
-            return preg_split('/\s/', strtr($text, Banana::$spool->ids));
+            $text = preg_split('/\s/', str_replace('><', '> <', $refs['references']));
+            foreach ($text as $id=>&$value) {
+                if (isset(Banana::$spool->ids[$value])) {
+                    $value = Banana::$spool->ids[$value];
+                } else {
+                    unset($text[$id]);
+                }
+            }
+            return $text;
         } elseif (isset($refs['in-reply-to']) && isset(Banana::$spool->ids[$refs['in-reply-to']])) {
             return array(Banana::$spool->ids[$refs['in-reply-to']]);
         } else {
index e57cb6a..71e1bee 100644 (file)
@@ -260,10 +260,10 @@ class BananaMimePart
             if (!is_utf8($val)) {
                 $val = utf8_encode($val);
             }
-        } else {
+        } elseif (strpos($val, '=') !== false) {
             $val = preg_replace('/(=\?.*?\?[bq]\?.*?\?=) (=\?.*?\?[bq]\?.*?\?=)/i', '\1\2', $val);
             $val = preg_replace('/=\?(.*?)\?([bq])\?(.*?)\?=/ie', 'BananaMimePart::_decodeHeader("\1", "\2", "\3")', $val);
-        }    
+        }
     }
 
     static public function &parseHeaders(array &$lines)
index 17aaeba..9318332 100644 (file)
@@ -153,10 +153,11 @@ class BananaNNTP extends BananaNNTPCore implements BananaProtocoleInterface
         $messages = array();
         foreach ($msg_headers as $header) {
             $headers = $this->xhdr($header, $firstid, $lastid);
-            array_walk($headers, array('BananaMimePart', 'decodeHeader'));
             $header  = strtolower($header);
             if ($header == 'date') {
                 $headers = array_map('strtotime', $headers);
+            } else {
+                array_walk($headers, array('BananaMimePart', 'decodeHeader'));
             }
             foreach ($headers as $id=>&$value) {
                 if (!isset($messages[$id])) {
index 7a48339..1dfe3a3 100644 (file)
@@ -134,20 +134,20 @@ class BananaSpool
 
     private function compare($a, $b)
     {
-        return ($b->date >= $a->date);
+        return ($this->overview[$b]->date >= $this->overview[$a]->date);
     }
 
     private function saveToFile()
     {
         $file = BananaSpool::spoolFilename($this->group);
-        uasort($this->overview, array($this, 'compare'));
 
         $this->roots = Array();
-        foreach($this->overview as $id=>$msg) {
+        foreach($this->overview as $id=>&$msg) {
             if (is_null($msg->parent)) {
                 $this->roots[] = $id;
             }
         }
+        usort($this->roots, array($this, 'compare'));
 
         if ($this->mode == Banana::SPOOL_ALL) {
             file_put_contents($file, serialize($this));