From 659cf14cdd8862a126b775392d59727a5e8a790b Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 20 Oct 2010 14:42:45 -0400
Subject: [PATCH] - Improve performance of messages counting using ESEARCH extension (RFC4731)
---
program/include/rcube_imap.php | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 5d90fe4..4bf7cac 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -539,19 +539,26 @@
// use SEARCH for message counting
else if ($this->skip_deleted) {
$search_str = "ALL UNDELETED";
+ $keys = array('COUNT');
+ $need_uid = false;
- // get message count and store in cache
- if ($mode == 'UNSEEN')
+ if ($mode == 'UNSEEN') {
$search_str .= " UNSEEN";
- // get message count using SEARCH
- // not very performant but more precise (using UNDELETED)
- $index = $this->conn->search($mailbox, $search_str);
+ }
+ else if ($status) {
+ $keys[] = 'MAX';
+ $need_uid = true;
+ }
- $count = is_array($index) ? count($index) : 0;
+ // get message count using (E)SEARCH
+ // not very performant but more precise (using UNDELETED)
+ $index = $this->conn->search($mailbox, $search_str, $need_uid, $keys);
+
+ $count = is_array($index) ? $index['COUNT'] : 0;
if ($mode == 'ALL' && $status) {
$this->set_folder_stats($mailbox, 'cnt', $count);
- $this->set_folder_stats($mailbox, 'maxuid', $index ? $this->_id2uid(max($index), $mailbox) : 0);
+ $this->set_folder_stats($mailbox, 'maxuid', is_array($index) ? $index['MAX'] : 0);
}
}
else {
--
Gitblit v1.9.1