From 309f49f09bc8b663a3ddf834ca0e79f909a0928c Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 04 Jun 2010 05:58:37 -0400
Subject: [PATCH] - performance improvement: skip SEARCH command when mailbox is empty and SEARCH is called just after SELECT

---
 program/include/rcube_imap.php         |    6 +-----
 program/include/rcube_imap_generic.php |    7 +++++++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 09ea4df..55b0820 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -476,11 +476,7 @@
                 $search_str .= " UNSEEN";
             // get message count using SEARCH
             // not very performant but more precise (using UNDELETED)
-            // disable THREADS for this request
-            $threads = $this->threading;
-            $this->threading = false;
-            $index = $this->_search_index($mailbox, $search_str);
-            $this->threading = $threads;
+            $index = $this->conn->search($mailbox, $search_str);
 
             $count = is_array($index) ? count($index) : 0;
 
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 461beec..ab37902 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -1584,10 +1584,17 @@
 
     function search($folder, $criteria, $return_uid=false)
     {
+        $old_sel = $this->selected;
+
 	    if (!$this->select($folder)) {
     		return false;
 	    }
 
+        // return empty result when folder is empty and we're just after SELECT
+        if ($old_sel != $folder && !$this->exists) {
+            return array();
+	    }
+
     	$data = '';
 	    $query = 'srch1 ' . ($return_uid ? 'UID ' : '') . 'SEARCH ' . chop($criteria);
 

--
Gitblit v1.9.1