Changeset 5316 in subversion


Ignore:
Timestamp:
Oct 6, 2011 11:49:33 AM (20 months ago)
Author:
alec
Message:
  • Improve performance by storing sorted mailbox list in the cache
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_imap.php

    r5309 r5316  
    29212921     * @param   bool    $skip_sort Enable to return unsorted list (for better performance) 
    29222922     * 
    2923      * @return  array   List of mailboxes/folders 
     2923     * @return  array   List of folders 
    29242924     * @access  public 
    29252925     */ 
    29262926    function list_mailboxes($root='', $name='*', $filter=null, $rights=null, $skip_sort=false) 
    29272927    { 
     2928        $cache_key = $root.':'.$name; 
     2929        if (!empty($filter)) { 
     2930            $cache_key .= ':'.(is_string($filter) ? $filter : serialize($filter)); 
     2931        } 
     2932        $cache_key .= ':'.$rights; 
     2933        $cache_key = 'mailboxes.'.md5($cache_key); 
     2934 
     2935        // get cached folder list 
     2936        $a_mboxes = $this->get_cache($cache_key); 
     2937        if (is_array($a_mboxes)) { 
     2938            return $a_mboxes; 
     2939        } 
     2940 
    29282941        $a_mboxes = $this->_list_mailboxes($root, $name, $filter, $rights); 
     2942 
     2943        if (!is_array($a_mboxes)) { 
     2944            return array(); 
     2945        } 
     2946 
     2947        // filter folders list according to rights requirements 
     2948        if ($rights && $this->get_capability('ACL')) { 
     2949            $a_mboxes = $this->filter_rights($a_mboxes, $rights); 
     2950        } 
    29292951 
    29302952        // INBOX should always be available 
     
    29332955        } 
    29342956 
    2935         // sort mailboxes 
    2936         if (!$skip_sort) { 
     2957        // sort mailboxes (always sort for cache) 
     2958        if (!$skip_sort || $this->cache) { 
    29372959            $a_mboxes = $this->_sort_mailbox_list($a_mboxes); 
    29382960        } 
     2961 
     2962        // write mailboxlist to cache 
     2963        $this->update_cache($cache_key, $a_mboxes); 
    29392964 
    29402965        return $a_mboxes; 
     
    29562981    private function _list_mailboxes($root='', $name='*', $filter=null, $rights=null) 
    29572982    { 
    2958         $cache_key = $root.':'.$name; 
    2959         if (!empty($filter)) { 
    2960             $cache_key .= ':'.(is_string($filter) ? $filter : serialize($filter)); 
    2961         } 
    2962         $cache_key .= ':'.$rights; 
    2963  
    2964         $cache_key = 'mailboxes.'.md5($cache_key); 
    2965  
    2966         // get cached folder list 
    2967         $a_mboxes = $this->get_cache($cache_key); 
    2968         if (is_array($a_mboxes)) { 
    2969             return $a_mboxes; 
    2970         } 
    2971  
    29722983        $a_defaults = $a_out = array(); 
    29732984 
     
    29802991        } 
    29812992        else if (!$this->conn->connected()) { 
    2982            return array(); 
     2993           return null; 
    29832994        } 
    29842995        else { 
     
    30273038            $a_folders = array(); 
    30283039        } 
    3029  
    3030         // filter folders list according to rights requirements 
    3031         if ($rights && $this->get_capability('ACL')) { 
    3032             $a_folders = $this->filter_rights($a_folders, $rights); 
    3033         } 
    3034  
    3035         // write mailboxlist to cache 
    3036         $this->update_cache($cache_key, $a_folders); 
    30373040 
    30383041        return $a_folders; 
Note: See TracChangeset for help on using the changeset viewer.