From 5e90d34a2e2d4dee490f7b50796bf0d4f75a8d1a Mon Sep 17 00:00:00 2001 From: nehresma Date: Sat, 5 Feb 2000 17:02:05 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@191 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/date.php | 52 +++++++++++++++++++++++++---------- functions/mailbox.php | 14 ++++------ functions/mailbox_display.php | 18 +++++++----- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/functions/date.php b/functions/date.php index d8031c9f..b4b1a7f8 100644 --- a/functions/date.php +++ b/functions/date.php @@ -196,21 +196,43 @@ ** 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); } ?> diff --git a/functions/mailbox.php b/functions/mailbox.php index 45d9021a..f5aba2f1 100644 --- a/functions/mailbox.php +++ b/functions/mailbox.php @@ -114,25 +114,21 @@ ** 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. **/ - function getMessageFlags($imapConnection, $j, &$flags) { + function getMessageFlags($imapConnection, $low, $high, &$flags) { /** * 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); $count = 0; while ((substr($read, 0, 15) != "messageFetch OK") && (substr($read, 0, 16) != "messageFetch BAD")) { if (strpos($read, "FLAGS")) { $read = ereg_replace("\(", "", $read); $read = ereg_replace("\)", "", $read); + $read = str_replace("\\", "", $read); $read = substr($read, strpos($read, "FLAGS")+6, strlen($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 { - $flags[0] = "None"; + $flags[$count][0] = "None"; } $count++; $read = fgets($imapConnection, 1024); diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 981f1b67..a4ed4b0f 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -7,7 +7,6 @@ ** table row that has sender, date, subject, etc... ** **/ - function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen, $mailbox, $sort, $startMessage) { require ("../config/config.php"); @@ -37,6 +36,7 @@ if (1 <= $numMessages) { getMessageHeaders($imapConnection, 1, $numMessages, $from, $subject, $date); + getMessageFlags($imapConnection, 1, $numMessages, $flags); } $j = 0; @@ -54,15 +54,14 @@ $messages[$j]["FLAG_SEEN"] = false; $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; } - else if ($flags[$num] == "Answered") { + else if ($flags[$j][$num] == "Answered") { $messages[$j]["FLAG_ANSWERED"] = true; } - else if ($flags[$num] == "Seen") { + else if ($flags[$j][$num] == "Seen") { $messages[$j]["FLAG_SEEN"] = true; } $num++; @@ -100,11 +99,13 @@ ** 2 = Name (up) ** 3 = Name (dn) **/ + if ($sort == 0) $msgs = ary_sort($msgs, "TIME_STAMP", -1); else if ($sort == 1) $msgs = ary_sort($msgs, "TIME_STAMP", 1); else { + $original = $msgs; $i = 0; while ($i < count($msgs)) { @@ -127,10 +128,14 @@ $i = 0; while ($i < count($msgs)) { $j = 0; + $loop = true; while ($j < count($original)) { if ($msgs[$i]["ID"] == $original[$j]["ID"]) { $msgs[$i]["FROM"] = $original[$j]["FROM"]; $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"]; + + // exit out of this loop if we find the thing. + $j = count($original) + 1; } $j++; } @@ -149,7 +154,6 @@ $prevGroup = $startMessage - 25; $urlMailbox = urlencode($mailbox); - /** This is the beginning of the message list table. It wraps around all messages */ echo ""; -- 2.25.1