فهرست منبع

increased performance of reading mailboxes 20-30% by doing 2 things:
1. Read message flags in at same time as headers
2. Sped up the getTimeStamp function in date.php

nehresma 25 سال پیش
والد
کامیت
3f92b233e3
3فایلهای تغییر یافته به همراه53 افزوده شده و 31 حذف شده
  1. 37 15
      functions/date.php
  2. 5 9
      functions/mailbox.php
  3. 11 7
      functions/mailbox_display.php

+ 37 - 15
functions/date.php

@@ -196,21 +196,43 @@
        **        and everything would be bumped up one.
        **        and everything would be bumped up one.
        **/
        **/
 
 
-      if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
-         $d[0] = getHour(trim($dateParts[4]));
-         $d[1] = getMinute(trim($dateParts[4]));
-         $d[2] = getSecond(trim($dateParts[4]));
-         $d[3] = getMonthNum(trim($dateParts[2]));
-         $d[4] = getDayOfMonth(trim($dateParts[1]));
-         $d[5] = getYear(trim($dateParts[3]));
-         return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[5]);
+      // Simply check to see if the first element in the dateParts array is an integer or not.
+      //    Since the day of week is optional, this check is needed.  
+      //    
+      //    The old code used eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp) 
+      //    to find if the first element was the day of week or day of month.  This is an
+      //    expensive call (processing time) to have inside a loop.  Doing it this way saves
+      //    quite a bit of time for large mailboxes.
+      //
+      //    It is also quicker to call explode only once rather than the 3 times it was getting
+      //    called by calling the functions getHour, getMinute, and getSecond.
+      //
+      if (intval(trim($dateParts[0])) > 0) {
+         $time = explode(":", $dateParts[3]);
+         $d[0] = $time[0];
+         $d[1] = $time[1];
+         $d[2] = $time[2];
+         $d[3] = getMonthNum(trim($dateParts[1]));
+         $d[4] = getDayOfMonth(trim($dateParts[0]));
+         $d[5] = getYear(trim($dateParts[2]));
+         return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[4]);
       }
       }
-      $d[0] = getHour(trim($dateParts[3]));
-      $d[1] = getMinute(trim($dateParts[3]));
-      $d[2] = getSecond(trim($dateParts[3]));
-      $d[3] = getMonthNum(trim($dateParts[1]));
-      $d[4] = getDayOfMonth(trim($dateParts[0]));
-      $d[5] = getYear(trim($dateParts[2]));
-      return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[4]);
+      $time = explode(":", $dateParts[4]);
+      $d[0] = $time[0];
+      $d[1] = $time[1];
+      $d[2] = $time[2];
+      $d[3] = getMonthNum(trim($dateParts[2]));
+      $d[4] = getDayOfMonth(trim($dateParts[1]));
+      $d[5] = getYear(trim($dateParts[3]));
+      return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[5]);
+   }
+
+   // I use this function for profiling.  Should never be called in actual versions of squirrelmail
+   //    released to public.
+   function getmicrotime() {
+      $mtime = microtime();
+      $mtime = explode(" ",$mtime);
+      $mtime = $mtime[1] + $mtime[0];
+      return ($mtime);
    }
    }
 ?>
 ?>

+ 5 - 9
functions/mailbox.php

@@ -114,25 +114,21 @@
     **  individually.  I'm not sure why it happens like that, but that's what my
     **  individually.  I'm not sure why it happens like that, but that's what my
     **  testing found.  Perhaps later I will be proven wrong and this will change.
     **  testing found.  Perhaps later I will be proven wrong and this will change.
     **/
     **/
-   function getMessageFlags($imapConnection, $j, &$flags) {
+   function getMessageFlags($imapConnection, $low, $high, &$flags) {
       /**   * 2 FETCH (FLAGS (\Answered \Seen))   */
       /**   * 2 FETCH (FLAGS (\Answered \Seen))   */
-      fputs($imapConnection, "messageFetch FETCH $j:$j FLAGS\n");
+      fputs($imapConnection, "messageFetch FETCH $low:$high FLAGS\n");
       $read = fgets($imapConnection, 1024);
       $read = fgets($imapConnection, 1024);
       $count = 0;
       $count = 0;
       while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
       while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) {
          if (strpos($read, "FLAGS")) {
          if (strpos($read, "FLAGS")) {
             $read = ereg_replace("\(", "", $read);
             $read = ereg_replace("\(", "", $read);
             $read = ereg_replace("\)", "", $read);
             $read = ereg_replace("\)", "", $read);
+            $read = str_replace("\\", "", $read);
             $read = substr($read, strpos($read, "FLAGS")+6, strlen($read));
             $read = substr($read, strpos($read, "FLAGS")+6, strlen($read));
             $read = trim($read);
             $read = trim($read);
-            $flags = explode(" ", $read);;
-            $s = 0;
-            while ($s < count($flags)) {
-               $flags[$s] = substr($flags[$s], 1, strlen($flags[$s]));
-               $s++;
-            }
+            $flags[$count] = explode(" ", $read);;
          } else {
          } else {
-            $flags[0] = "None";
+            $flags[$count][0] = "None";
          }
          }
          $count++;
          $count++;
          $read = fgets($imapConnection, 1024);
          $read = fgets($imapConnection, 1024);

+ 11 - 7
functions/mailbox_display.php

@@ -7,7 +7,6 @@
     **  table row that has sender, date, subject, etc...
     **  table row that has sender, date, subject, etc...
     **
     **
     **/
     **/
-
    function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
    function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) {
       require ("../config/config.php");
       require ("../config/config.php");
 
 
@@ -37,6 +36,7 @@
 
 
       if (1 <= $numMessages) {
       if (1 <= $numMessages) {
          getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
          getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date);
+         getMessageFlags($imapConnection, 1, $numMessages, $flags);
       }
       }
 
 
       $j = 0;
       $j = 0;
@@ -54,15 +54,14 @@
          $messages[$j]["FLAG_SEEN"] = false;
          $messages[$j]["FLAG_SEEN"] = false;
 
 
          $num = 0;
          $num = 0;
-         getMessageFlags($imapConnection, $j+1, $flags);
-         while ($num < count($flags)) {
-            if ($flags[$num] == "Deleted") {
+         while ($num < count($flags[$j])) {
+            if ($flags[$j][$num] == "Deleted") {
                $messages[$j]["FLAG_DELETED"] = true;
                $messages[$j]["FLAG_DELETED"] = true;
             }
             }
-            else if ($flags[$num] == "Answered") {
+            else if ($flags[$j][$num] == "Answered") {
                $messages[$j]["FLAG_ANSWERED"] = true;
                $messages[$j]["FLAG_ANSWERED"] = true;
             }
             }
-            else if ($flags[$num] == "Seen") {
+            else if ($flags[$j][$num] == "Seen") {
                $messages[$j]["FLAG_SEEN"] = true;
                $messages[$j]["FLAG_SEEN"] = true;
             }
             }
             $num++;
             $num++;
@@ -100,11 +99,13 @@
           ** 2 = Name (up)
           ** 2 = Name (up)
           ** 3 = Name (dn)
           ** 3 = Name (dn)
           **/
           **/
+
          if ($sort == 0)
          if ($sort == 0)
             $msgs = ary_sort($msgs, "TIME_STAMP", -1);
             $msgs = ary_sort($msgs, "TIME_STAMP", -1);
          else if ($sort == 1)
          else if ($sort == 1)
             $msgs = ary_sort($msgs, "TIME_STAMP", 1);
             $msgs = ary_sort($msgs, "TIME_STAMP", 1);
          else {
          else {
+
             $original = $msgs;
             $original = $msgs;
             $i = 0;
             $i = 0;
             while ($i < count($msgs)) {
             while ($i < count($msgs)) {
@@ -127,10 +128,14 @@
             $i = 0;
             $i = 0;
             while ($i < count($msgs)) {
             while ($i < count($msgs)) {
                $j = 0;
                $j = 0;
+               $loop = true;
                while ($j < count($original)) {
                while ($j < count($original)) {
                   if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
                   if ($msgs[$i]["ID"] == $original[$j]["ID"]) {
                      $msgs[$i]["FROM"] = $original[$j]["FROM"];
                      $msgs[$i]["FROM"] = $original[$j]["FROM"];
                      $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
                      $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"];
+
+                     // exit out of this loop if we find the thing.
+                     $j = count($original) + 1;
                   }
                   }
                   $j++;
                   $j++;
                }
                }
@@ -149,7 +154,6 @@
       $prevGroup = $startMessage - 25;
       $prevGroup = $startMessage - 25;
       $urlMailbox = urlencode($mailbox);
       $urlMailbox = urlencode($mailbox);
 
 
-
       /** This is the beginning of the message list table.  It wraps around all messages */
       /** This is the beginning of the message list table.  It wraps around all messages */
       echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";
       echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1>";