Changeset 4162 in subversion


Ignore:
Timestamp:
Oct 29, 2010 2:02:19 PM (3 years ago)
Author:
alec
Message:
  • Improve performance of message cache status checking when skip_disabled=true
Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4160 r4162  
    5858- Plugin API: add possibility to disable plugin in framed mode, 'noframe' property 
    5959- Improve performance of setting IMAP flags using .SILENT suffix 
     60- Improve performance of message cache status checking with skip_disabled=true 
    6061 
    6162RELEASE 0.4.2 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r4161 r4162  
    547547                $search_str .= " UNSEEN"; 
    548548            } 
    549             else if ($status) { 
    550                 $keys[]   = 'MAX'; 
    551                 $need_uid = true; 
     549            else { 
     550                if ($this->caching_enabled) { 
     551                    $keys[] = 'ALL'; 
     552                } 
     553                if ($status) { 
     554                    $keys[]   = 'MAX'; 
     555                    $need_uid = true; 
     556                } 
    552557            } 
    553558 
     
    558563            $count = is_array($index) ? $index['COUNT'] : 0; 
    559564 
    560             if ($mode == 'ALL' && $status) { 
    561                 $this->set_folder_stats($mailbox, 'cnt', $count); 
    562                 $this->set_folder_stats($mailbox, 'maxuid', is_array($index) ? $index['MAX'] : 0); 
     565            if ($mode == 'ALL') { 
     566                if ($need_uid && $this->caching_enabled) { 
     567                    // Save messages index for check_cache_status() 
     568                    $this->icache['all_undeleted_idx'] = $index['ALL']; 
     569                } 
     570                if ($status) { 
     571                    $this->set_folder_stats($mailbox, 'cnt', $count); 
     572                    $this->set_folder_stats($mailbox, 'maxuid', is_array($index) ? $index['MAX'] : 0); 
     573                } 
    563574            } 
    564575        } 
     
    36473658 
    36483659        // empty mailbox 
    3649         if (!$msg_count) 
     3660        if (!$msg_count) { 
    36503661            return $cache_count ? -2 : 1; 
     3662        } 
    36513663 
    36523664        if ($cache_count == $msg_count) { 
    36533665            if ($this->skip_deleted) { 
    3654                     $h_index = $this->conn->fetchHeaderIndex($mailbox, "1:*", 'UID', $this->skip_deleted); 
    3655  
    3656                 // Save index in internal cache, will be used when syncing the cache 
    3657                 $this->icache['folder_index'] = $h_index; 
    3658  
    3659                 if (empty($h_index)) 
    3660                     return -2; 
    3661  
    3662                     if (sizeof($h_index) == $cache_count) { 
    3663                         $cache_index = array_flip($cache_index); 
    3664                         foreach ($h_index as $idx => $uid) 
    3665                         unset($cache_index[$uid]); 
    3666  
    3667                         if (empty($cache_index)) 
    3668                             return 1; 
    3669                     } 
    3670                     return -2; 
     3666                if (!empty($this->icache['all_undeleted_idx'])) { 
     3667                    $uids = rcube_imap_generic::uncompressMessageSet($this->icache['all_undeleted_idx']); 
     3668                    $uids = array_flip($uids); 
     3669                    foreach ($cache_index as $uid) { 
     3670                        unset($uids[$uid]); 
     3671                    } 
     3672                } 
     3673                else { 
     3674                    // get all undeleted messages excluding cached UIDs 
     3675                    $uids = $this->search_once($mailbox, 'ALL UNDELETED NOT UID '. 
     3676                        rcube_imap_generic::compressMessageSet($cache_index)); 
     3677                } 
     3678                if (empty($uids)) { 
     3679                    return 1; 
     3680                } 
    36713681            } else { 
    36723682                // get UID of the message with highest index 
     
    36753685 
    36763686                // uids of highest message matches -> cache seems OK 
    3677                 if ($cache_uid == $uid) 
     3687                if ($cache_uid == $uid) { 
    36783688                    return 1; 
     3689                } 
    36793690            } 
    36803691            // cache is dirty 
    36813692            return -1; 
    36823693        } 
     3694 
    36833695        // if cache count differs less than 10% report as dirty 
    3684         else if (abs($msg_count - $cache_count) < $msg_count/10) 
    3685             return -1; 
    3686         else 
    3687             return -2; 
     3696        return (abs($msg_count - $cache_count) < $msg_count/10) ? -1 : -2; 
    36883697    } 
    36893698 
  • trunk/roundcubemail/program/include/rcube_imap_generic.php

    r4161 r4162  
    10091009 
    10101010            // message IDs 
    1011             if (is_array($add)) 
    1012                     $add = $this->compressMessageSet(join(',', $add)); 
     1011            if (!empty($add)) 
     1012                    $add = $this->compressMessageSet($add); 
    10131013 
    10141014            list($code, $response) = $this->execute($is_uid ? 'UID SORT' : 'SORT', 
     
    10271027    { 
    10281028            if (is_array($message_set)) { 
    1029                     if (!($message_set = $this->compressMessageSet(join(',', $message_set)))) 
     1029                    if (!($message_set = $this->compressMessageSet($message_set))) 
    10301030                            return false; 
    10311031            } else { 
     
    11511151    } 
    11521152 
    1153     private function compressMessageSet($messages, $force=false) 
     1153    static function compressMessageSet($messages, $force=false) 
    11541154    { 
    11551155            // given a comma delimited list of independent mid's, 
    11561156            // compresses by grouping sequences together 
    11571157 
    1158         if (!is_array($message_set)) { 
     1158        if (!is_array($messages)) { 
    11591159                // if less than 255 bytes long, let's not bother 
    11601160                if (!$force && strlen($messages)<255) { 
     
    12001200    } 
    12011201 
     1202    static function uncompressMessageSet($messages) 
     1203    { 
     1204            $result   = array(); 
     1205            $messages = explode(',', $messages); 
     1206 
     1207        foreach ($messages as $part) { 
     1208            $items = explode(':', $part); 
     1209            $max   = max($items[0], $items[1]); 
     1210 
     1211            for ($x=$items[0]; $x<=$max; $x++) { 
     1212                $result[] = $x; 
     1213            } 
     1214        } 
     1215 
     1216        return $result; 
     1217    } 
     1218 
    12021219    /** 
    12031220     * Returns message sequence identifier 
     
    12651282                    return false; 
    12661283            } 
    1267  
    1268             if (is_array($message_set)) 
    1269                     $message_set = join(',', $message_set); 
    12701284 
    12711285            $message_set = $this->compressMessageSet($message_set); 
     
    18251839                        $result['MAX'] = !empty($response) ? max($response) : 0; 
    18261840                    if (in_array('ALL', $items)) 
    1827                         $result['ALL'] = $this->compressMessageSet(implode(',', $response), true); 
     1841                        $result['ALL'] = $this->compressMessageSet($response, true); 
    18281842 
    18291843                    return $result;                     
Note: See TracChangeset for help on using the changeset viewer.