Changeset b32cb21 in github


Ignore:
Timestamp:
Jun 23, 2009 3:17:49 AM (4 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
ac62299
Parents:
ad84f9c
Message:
  • more preformance improvements of messages caching + some code refactoring
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_imap.php

    rad84f9c rb32cb21  
    15461546 
    15471547    // reload message headers if cached 
    1548     $cache_key = $mailbox.'.msg'; 
    15491548    if ($this->caching_enabled) 
    15501549      { 
     1550      $cache_key = $mailbox.'.msg'; 
    15511551      $this->remove_message_cache($cache_key, $uids); 
    15521552 
     
    16481648    // update cached message headers 
    16491649    $cache_key = $from_mbox.'.msg'; 
    1650     if ($moved && ($a_cache_index = $this->get_message_cache_index($cache_key))) 
    1651       { 
    1652       $start_index = 100000; 
    1653       foreach ($a_uids as $uid) 
    1654         { 
    1655         if (($index = array_search($uid, $a_cache_index)) !== FALSE) 
    1656           $start_index = min($index, $start_index); 
    1657         } 
    1658  
     1650    if ($moved && $start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) { 
    16591651      // clear cache from the lowest index on 
    1660       if ($start_index < 100000) 
    1661         $this->clear_message_cache($cache_key, $start_index); 
     1652      $this->clear_message_cache($cache_key, $start_index); 
    16621653      } 
    16631654 
     
    17041695    // remove deleted messages from cache 
    17051696    $cache_key = $mailbox.'.msg'; 
    1706     if ($deleted && ($a_cache_index = $this->get_message_cache_index($cache_key))) 
    1707       { 
    1708       $start_index = 100000; 
    1709       foreach ($a_uids as $uid) 
    1710         { 
    1711         if (($index = array_search($uid, $a_cache_index)) !== FALSE) 
    1712           $start_index = min($index, $start_index); 
    1713         } 
    1714  
     1697    if ($deleted && $start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) { 
    17151698      // clear cache from the lowest index on 
    1716       if ($start_index < 100000) 
    1717         $this->clear_message_cache($cache_key, $start_index); 
     1699      $this->clear_message_cache($cache_key, $start_index); 
    17181700      } 
    17191701 
     
    20602042    if (!isset($this->cache[$key]) && $this->caching_enabled) 
    20612043      { 
    2062       $cache_data = $this->_read_cache_record('IMAP.'.$key); 
    2063       $this->cache[$key] = strlen($cache_data) ? unserialize($cache_data) : FALSE; 
     2044      return $this->_read_cache_record($key); 
    20642045      } 
    20652046     
     
    20872068        { 
    20882069        if ($this->cache_changes[$key]) 
    2089           $this->_write_cache_record('IMAP.'.$key, serialize($data)); 
     2070          $this->_write_cache_record($key, serialize($data)); 
    20902071        } 
    20912072      }     
     
    21032084      { 
    21042085      foreach ($this->cache as $key => $data) 
    2105         $this->_clear_cache_record('IMAP.'.$key); 
     2086        $this->_clear_cache_record($key); 
    21062087 
    21072088      $this->cache = array(); 
     
    21112092    else 
    21122093      { 
    2113       $this->_clear_cache_record('IMAP.'.$key); 
     2094      $this->_clear_cache_record($key); 
    21142095      $this->cache_changes[$key] = FALSE; 
    21152096      unset($this->cache[$key]); 
     
    21222103  function _read_cache_record($key) 
    21232104    { 
    2124     $cache_data = FALSE; 
    2125      
    21262105    if ($this->db) 
    21272106      { 
    21282107      // get cached data from DB 
    21292108      $sql_result = $this->db->query( 
    2130         "SELECT cache_id, data 
     2109        "SELECT cache_id, data, cache_key 
    21312110         FROM ".get_table_name('cache')." 
    21322111         WHERE  user_id=? 
    2133          AND    cache_key=?", 
    2134         $_SESSION['user_id'], 
    2135         $key); 
    2136  
    2137       if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
     2112         AND cache_key LIKE 'IMAP.%'", 
     2113        $_SESSION['user_id']); 
     2114 
     2115      while ($sql_arr = $this->db->fetch_assoc($sql_result)) 
    21382116        { 
    2139         $cache_data = $sql_arr['data']; 
    2140         $this->cache_keys[$key] = $sql_arr['cache_id']; 
     2117        $sql_key = preg_replace('/^IMAP\./', '', $sql_arr['cache_key']); 
     2118        $this->cache_keys[$sql_key] = $sql_arr['cache_id']; 
     2119        $this->cache[$sql_key] = $sql_arr['data'] ? unserialize($sql_arr['data']) : FALSE; 
    21412120        } 
    21422121      } 
    21432122 
    2144     return $cache_data; 
     2123    return $this->cache[$key]; 
    21452124    } 
    21462125 
     
    21622141         AND    cache_key=?", 
    21632142        $_SESSION['user_id'], 
    2164         $key); 
     2143        'IMAP.'.$key); 
    21652144                                      
    21662145      if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
     
    21802159        $data, 
    21812160        $_SESSION['user_id'], 
    2182         $key); 
     2161        'IMAP.'.$key); 
    21832162      } 
    21842163    // add new cache record 
     
    21902169         VALUES (".$this->db->now().", ?, ?, ?)", 
    21912170        $_SESSION['user_id'], 
    2192         $key, 
     2171        'IMAP.'.$key, 
    21932172        $data); 
    21942173      } 
     
    22052184       AND    cache_key=?", 
    22062185      $_SESSION['user_id'], 
    2207       $key); 
     2186      'IMAP.'.$key); 
    22082187    } 
    22092188 
     
    24632442    } 
    24642443 
    2465  
     2444  /** 
     2445   * @access private 
     2446   */ 
     2447  function get_message_cache_index_min($key, $uids=NULL) 
     2448    { 
     2449    if (!$this->caching_enabled) 
     2450      return; 
     2451     
     2452    $sql_result = $this->db->query( 
     2453      "SELECT MIN(idx) AS minidx 
     2454      FROM ".get_table_name('messages')." 
     2455      WHERE  user_id=? 
     2456      AND    cache_key=?" 
     2457      .(!empty($uids) ? " AND uid IN (".$this->db->array2list($uids, 'integer').")" : ''), 
     2458      $_SESSION['user_id'], 
     2459      $key); 
     2460 
     2461    if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
     2462      return $sql_arr['minidx']; 
     2463    else 
     2464      return 0;   
     2465    } 
    24662466 
    24672467 
Note: See TracChangeset for help on using the changeset viewer.