Optimize Horde_Imap_Client_Thread for storage
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Mar 2009 20:39:09 +0000 (14:39 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Mar 2009 21:43:59 +0000 (15:43 -0600)
Now that it may be serialized and stored in cache, optimize the internal
data structures.  New storage saves approx. 60%.

framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
framework/Imap_Client/lib/Horde/Imap/Client/Thread.php

index db88b5d..e5907df 100644 (file)
@@ -1473,11 +1473,15 @@ abstract class Horde_Imap_Client_Base
      *                message sequence number (if 'sequence' is true). Values
      *                of each entry:
      * <pre>
-     * 'base' - (integer) The UID of the base message. Is null if this is the
-     *          only message in the thread.
-     * 'last' - (boolean) Is this the last message in a subthread?
-     * 'level' - (integer) The thread level of this message (1 = base).
-     * 'uid' - (integer) The UID of the message.
+     * 'b' (base) - (integer) [OPTIONAL] The ID of the base message. Is not
+     *              set, this is the only message in the thread.
+     *              DEFAULT: Only message in thread
+     * 'l' (level) - (integer) [OPTIONAL] The thread level of this
+     *               message (1 = base).
+     *               DEFAULT: 0
+     * 's' (subthread) - (boolean) [OPTIONAL] Are there more messages in this
+     *                   subthread?
+     *                   DEFAULT: No
      * </pre>
      * @throws Horde_Imap_Client_Exception
      */
index 821fb3b..98584ac 100644 (file)
@@ -1962,12 +1962,21 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 if (is_null($tp['base']) && ($level || $cnt)) {
                     $tp['base'] = $val;
                 }
-                $tp['resp'][$val] = array(
-                    'base' => $tp['base'],
-                    'last' => $islast,
-                    'level' => $level++,
-                    'id' => $val
-                );
+
+                $tp['resp'][$val] = array();
+                $ptr = &$tp['resp'][$val];
+
+                if (!is_null($tp['base'])) {
+                    $ptr['b'] = $tp['base'];
+                }
+
+                if (!$islast) {
+                    $ptr['s'] = true;
+                }
+
+                if ($level++) {
+                    $ptr['l'] = $level;
+                }
             }
             $islast = true;
         }
index a5cc413..e5269f7 100644 (file)
@@ -61,8 +61,8 @@ class Horde_Imap_Client_Thread
      */
     public function getThreadIndent($index)
     {
-        return isset($this->_thread[$index]['level'])
-            ? $this->_thread[$index]['level']
+        return isset($this->_thread[$index])
+            ? (isset($this->_thread[$index]['l']) ? $this->_thread[$index]['l'] : 0)
             : false;
     }
 
@@ -76,8 +76,8 @@ class Horde_Imap_Client_Thread
      */
     public function getThreadBase($index)
     {
-        return !empty($this->_thread[$index]['base'])
-            ? $this->_thread[$index]['base']
+        return isset($this->_thread[$index])
+            ? (isset($this->_thread[$index]['b']) ? $this->_thread[$index]['b'] : null)
             : false;
     }
 
@@ -92,9 +92,7 @@ class Horde_Imap_Client_Thread
      */
     public function lastInLevel($index)
     {
-        return !empty($this->_thread[$index]['last'])
-            ? $this->_thread[$index]['last']
-            : false;
+        return empty($this->_thread[$index]['s']);
     }
 
     /**
@@ -131,7 +129,7 @@ class Horde_Imap_Client_Thread
         while (list($k, $v) = each($this->_thread)) {
             if ($k == $begin) {
                 $in_thread = true;
-            } elseif ($in_thread && ($v['base'] != $begin)) {
+            } elseif ($in_thread && ($this->getThreadBase($k) != $begin)) {
                 break;
             }