Changeset 5029 in subversion


Ignore:
Timestamp:
Aug 8, 2011 8:14:49 AM (23 months ago)
Author:
alec
Message:
  • Fixed messages re-sorting with rcube_header_sorter
  • More "use UID where possible"
  • Improved parformance for case when id2uid() is called before listing messages
Location:
branches/devel-mcache/roundcubemail/program/include
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap.php

    r5028 r5029  
    892892        else if ($this->get_capability('SORT') && 
    893893            // Courier-IMAP provides SORT capability but allows to disable it by admin (#1486959) 
    894             ($msg_index = $this->conn->sort($mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')) !== false 
     894            ($msg_index = $this->conn->sort($mailbox, $this->sort_field, 
     895                $this->skip_deleted ? 'UNDELETED' : '', true)) !== false 
    895896        ) { 
    896897            if (!empty($msg_index)) { 
    897898                list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
    898899                $msg_index = array_slice($msg_index, $begin, $end-$begin); 
     900                $is_uid    = true; 
    899901 
    900902                if ($slice) 
     
    902904 
    903905                // fetch reqested headers from server 
    904                 $a_msg_headers = $this->fetch_headers($mailbox, $msg_index); 
     906                $a_msg_headers = $this->fetch_headers($mailbox, $msg_index, true); 
    905907            } 
    906908        } 
    907909        // fetch specified header for all messages and sort 
    908         else if ($a_index = $this->conn->fetchHeaderIndex($mailbox, "1:*", $this->sort_field, $this->skip_deleted)) { 
    909             asort($a_index); // ASC 
    910             $msg_index = array_keys($a_index); 
     910        else if ($msg_index = $this->conn->fetchHeaderIndex($mailbox, "1:*", 
     911            $this->sort_field, $this->skip_deleted, true) 
     912        ) { 
     913            asort($msg_index); // ASC 
     914            $msg_index = array_keys($msg_index); 
    911915            list($begin, $end) = $this->_get_message_range(count($msg_index), $page); 
    912916            $msg_index = array_slice($msg_index, $begin, $end-$begin); 
     917            $is_uid    = true; 
    913918 
    914919            if ($slice) 
     
    916921 
    917922            // fetch reqested headers from server 
    918             $a_msg_headers = $this->fetch_headers($mailbox, $msg_index); 
     923            $a_msg_headers = $this->fetch_headers($mailbox, $msg_index, true); 
    919924        } 
    920925 
     
    16621667 
    16631668            // Error, try with US-ASCII (RFC5256: SORT/THREAD must support US-ASCII and UTF-8, 
    1664             // but I've seen that Courier doesn't support UTF-8) 
     1669            // but I've seen Courier with disabled UTF-8 support) 
    16651670            if ($a_messages === false && $charset && $charset != 'US-ASCII') 
    16661671                $a_messages = $this->conn->sort($mailbox, $sort_field, 
     
    45004505    function sort_headers(&$headers) 
    45014506    { 
    4502         if (!empty($uids)) 
     4507        if (!empty($this->uids)) 
    45034508            uksort($headers, array($this, "compare_uids")); 
    45044509        else 
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap_cache.php

    r5028 r5029  
    9898        // Seek in internal cache 
    9999        if (array_key_exists('index', $this->icache[$mailbox]) 
    100             && ($this->icache[$mailbox]['index']['sort_field'] == $sort_field) 
     100            && ($sort_field == 'ANY' || $this->icache[$mailbox]['index']['sort_field'] == $sort_field) 
    101101        ) { 
    102102            if ($this->icache[$mailbox]['index']['sort_order'] == $sort_order) 
     
    122122        if (!empty($index)) { 
    123123            $exists = true; 
     124            if ($sort_field == 'ANY') { 
     125                $sort_field = $index['sort_field']; 
     126            } 
    124127 
    125128            // Check UIDVALIDITY 
     
    195198            } 
    196199        } 
    197  
    198         $this->icache[$mailbox]['index'] = array( 
    199             'result'     => $data, 
    200             'sort_field' => $sort_field, 
    201             'sort_order' => $sort_order, 
    202         ); 
    203  
    204         if ($data !== null) { 
    205             return $data; 
     200        else if ($sort_field == 'ANY') { 
     201            $sort_field = ''; 
    206202        } 
    207203 
    208204        // Index not found or not valid, get index from IMAP server 
    209         $data = array(); 
    210         if ($mbox_data['EXISTS']) { 
    211             // fetch sorted sequence numbers 
    212             $data_seq = $this->imap->message_index_direct($mailbox, $sort_field, $sort_order); 
    213             // fetch UIDs 
    214             if (!empty($data_seq)) { 
    215                 $data_uid = $this->imap->conn->fetchUIDs($mailbox, $data_seq); 
    216                 // build index 
    217                 if (!empty($data_uid)) { 
    218                     foreach ($data_seq as $seq) 
    219                         if ($uid = $data_uid[$seq]) 
    220                             $data[$seq] = $uid; 
    221                 } 
    222             } 
    223         } 
    224  
    225         if (is_array($data)) { 
     205        if ($data === null) { 
     206            $data = array(); 
     207            if ($mbox_data['EXISTS']) { 
     208                // fetch sorted sequence numbers 
     209                $data_seq = $this->imap->message_index_direct($mailbox, $sort_field, $sort_order); 
     210                // fetch UIDs 
     211                if (!empty($data_seq)) { 
     212                    // Seek in internal cache 
     213                    if (array_key_exists('index', $this->icache[$mailbox])) 
     214                        $data_uid = $this->icache[$mailbox]['index']['result']; 
     215                    else 
     216                        $data_uid = $this->imap->conn->fetchUIDs($mailbox, $data_seq); 
     217 
     218                    // build index 
     219                    if (!empty($data_uid)) { 
     220                        foreach ($data_seq as $seq) 
     221                            if ($uid = $data_uid[$seq]) 
     222                                $data[$seq] = $uid; 
     223                    } 
     224                } 
     225            } 
     226 
    226227            $in_data = implode(':', array( 
    227228                implode(',', array_keys($data)), 
    228229                implode(',', array_values($data)), 
    229230                $sort_order, 
    230                 (int)$this->skip_deleted, 
    231                 (int)$mbox_data['UIDVALIDITY'], 
     231                (int) $this->skip_deleted, 
     232                (int) $mbox_data['UIDVALIDITY'], 
    232233            )); 
    233234 
     
    246247                    ." VALUES (?, ?, ?, 0, ?, ".$this->db->now().")", 
    247248                    $this->userid, $mailbox, (string)$sort_field, $in_data); 
    248  
    249         } 
    250  
    251         return $this->icache[$mailbox]['index']['result'] = (array)$data; 
     249        } 
     250 
     251        $this->icache[$mailbox]['index'] = array( 
     252            'result'     => $data, 
     253            'sort_field' => $sort_field, 
     254            'sort_order' => $sort_order, 
     255        ); 
     256 
     257        return $this->icache[$mailbox]['index']['result']; 
    252258    } 
    253259 
     
    431437    function id2uid($mailbox, $id) 
    432438    { 
    433         $index = $this->get_index($mailbox); 
     439        $index = $this->get_index($mailbox, 'ANY'); 
    434440 
    435441        return $index[$id]; 
     
    445451    function uid2id($mailbox, $uid) 
    446452    { 
    447         $index = $this->get_index($mailbox); 
     453        $index = $this->get_index($mailbox, 'ANY'); 
    448454 
    449455        return array_search($uid, $index); 
     
    456462    private function get_index_row($mailbox, $sort_field, $threaded = false) 
    457463    { 
    458         // Get index from DB, for query with no sort_field specified 
    459         // we'll get most recent index data 
    460         $sql_result = $this->db->query( 
    461             "SELECT data, sort_field" 
    462             ." FROM ".get_table_name('cache_index') 
    463             ." WHERE user_id = ?" 
    464                 ." AND mailbox = ?" 
    465                 ." AND sort_field = ?" 
    466                 ." AND threaded = ?", 
    467             $this->userid, $mailbox, (string)$sort_field, (int)$threaded); 
     464        // Get index from DB 
     465        // There's a special case when we want most recent index 
     466        if ($sort_field == 'ANY') 
     467            $sql_result = $this->db->limitquery( 
     468                "SELECT data, sort_field" 
     469                ." FROM ".get_table_name('cache_index') 
     470                ." WHERE user_id = ?" 
     471                    ." AND mailbox = ?" 
     472                    ." AND threaded = ?" 
     473                ." ORDER BY changed DESC", 
     474                0, 1, $this->userid, $mailbox, (int)$threaded); 
     475        else 
     476            $sql_result = $this->db->query( 
     477                "SELECT data, sort_field" 
     478                ." FROM ".get_table_name('cache_index') 
     479                ." WHERE user_id = ?" 
     480                    ." AND mailbox = ?" 
     481                    ." AND threaded = ?" 
     482                    ." AND sort_field = ?", 
     483                $this->userid, $mailbox, (int)$threaded, (string)$sort_field); 
    468484 
    469485        if ($sql_arr = $this->db->fetch_assoc($sql_result)) { 
  • branches/devel-mcache/roundcubemail/program/include/rcube_imap_generic.php

    r5028 r5029  
    6262    public $forwarded = false; 
    6363    public $flagged = false; 
    64     public $has_children = false; 
    65     public $depth = 0; 
    66     public $unread_children = 0; 
    6764    public $others = array(); 
    6865} 
Note: See TracChangeset for help on using the changeset viewer.