Changeset 2676 in subversion


Ignore:
Timestamp:
Jun 24, 2009 7:49:49 AM (4 years ago)
Author:
alec
Message:
  • more performance improvements of caching
File:
1 edited

Legend:

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

    r2675 r2676  
    795795        // add message to cache 
    796796        if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) 
    797           $this->add_message_cache($cache_key, $headers->id, $headers); 
     797          $this->add_message_cache($cache_key, $headers->id, $headers, NULL, 
     798                !in_array((string)$headers->uid, $cache_index, true)); 
    798799 
    799800        $a_msg_headers[$headers->uid] = $headers; 
     
    913914      if (in_array((string)$uid, $cache_index, TRUE)) 
    914915        { 
    915         unset($cache_index[$id]);         
     916        unset($cache_index[$id]); 
    916917        } 
    917918       
     
    937938      if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $for_update), false, $this->fetch_add_headers)) 
    938939        foreach ($headers as $header) 
    939           $this->add_message_cache($cache_key, $header->id, $header); 
     940          $this->add_message_cache($cache_key, $header->id, $header, NULL, 
     941                in_array((string)$header->uid, $for_remove, true)); 
    940942      } 
    941943    } 
     
    10861088        $this->uid_id_map[$mailbox][$headers->uid] = $headers->id; 
    10871089 
    1088       $this->add_message_cache($mailbox.'.msg', $headers->id, $headers); 
     1090      $this->add_message_cache($mailbox.'.msg', $headers->id, $headers, NULL, true); 
    10891091      } 
    10901092 
     
    11041106    { 
    11051107    $cache_key = $this->mailbox.'.msg'; 
    1106     $headers = &$this->get_cached_message($cache_key, $uid, true); 
     1108    $headers = &$this->get_cached_message($cache_key, $uid); 
    11071109 
    11081110    // return cached message structure 
     
    22012203   * @return int -3 = off, -2 = incomplete, -1 = dirty 
    22022204   */ 
    2203   function check_cache_status($mailbox, $cache_key) 
     2205  private function check_cache_status($mailbox, $cache_key) 
    22042206  { 
    22052207    if (!$this->caching_enabled) 
     
    22472249   * @access private 
    22482250   */ 
    2249   function get_message_cache($key, $from, $to, $sort_field, $sort_order) 
     2251  private function get_message_cache($key, $from, $to, $sort_field, $sort_order) 
    22502252    { 
    22512253    $cache_key = "$key:$from:$to:$sort_field:$sort_order"; 
     
    22862288   * @access private 
    22872289   */ 
    2288   function &get_cached_message($key, $uid, $struct=false) 
     2290  private function &get_cached_message($key, $uid) 
    22892291    { 
    22902292    $internal_key = '__single_msg'; 
     
    22932295        ($struct && empty($this->cache[$internal_key][$uid]->structure)))) 
    22942296      { 
    2295       $sql_select = "idx, uid, headers" . ($struct ? ", structure" : ''); 
    22962297      $sql_result = $this->db->query( 
    2297         "SELECT $sql_select 
     2298        "SELECT idx, headers, structure 
    22982299         FROM ".get_table_name('messages')." 
    22992300         WHERE  user_id=? 
     
    23032304        $key, 
    23042305        $uid); 
     2306 
    23052307      if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
    23062308        { 
     2309        $this->uid_id_map[preg_replace('/\.msg$/', '', $key)][$uid] = $sql_arr['idx']; 
    23072310        $this->cache[$internal_key][$uid] = $this->db->decode(unserialize($sql_arr['headers'])); 
    23082311        if (is_object($this->cache[$internal_key][$uid]) && !empty($sql_arr['structure'])) 
     
    23172320   * @access private 
    23182321   */   
    2319   function get_message_cache_index($key, $force=FALSE, $sort_field='idx', $sort_order='ASC') 
     2322  private function get_message_cache_index($key, $force=FALSE, $sort_field='idx', $sort_order='ASC') 
    23202323    { 
    23212324    static $sa_message_index = array(); 
     
    23472350   * @access private 
    23482351   */ 
    2349   private function add_message_cache($key, $index, $headers, $struct=null) 
     2352  private function add_message_cache($key, $index, $headers, $struct=null, $force=false) 
    23502353    { 
    23512354    if (empty($key) || !is_object($headers) || empty($headers->uid)) 
     
    23532356 
    23542357    // add to internal (fast) cache 
    2355     $this->cache['__single_msg'][$headers->uid] = $headers; 
     2358    $this->cache['__single_msg'][$headers->uid] = clone $headers; 
    23562359    $this->cache['__single_msg'][$headers->uid]->structure = $struct; 
    23572360 
     
    23612364     
    23622365    // check for an existing record (probly headers are cached but structure not) 
    2363     $sql_result = $this->db->query( 
     2366    if (!$force) { 
     2367      $sql_result = $this->db->query( 
    23642368        "SELECT message_id 
    23652369         FROM ".get_table_name('messages')." 
     
    23712375        $key, 
    23722376        $headers->uid); 
     2377      if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
     2378        $message_id = $sql_arr['message_id']; 
     2379      } 
    23732380 
    23742381    // update cache record 
    2375     if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
     2382    if ($message_id) 
    23762383      { 
    23772384      $this->db->query( 
     
    23822389        serialize($this->db->encode(clone $headers)), 
    23832390        is_object($struct) ? serialize($this->db->encode(clone $struct)) : NULL, 
    2384         $sql_arr['message_id'] 
     2391        $message_id 
    23852392        ); 
    23862393      } 
     
    23952402        $index, 
    23962403        $headers->uid, 
    2397  
    23982404        (string)rc_substr($this->db->encode($this->decode_header($headers->subject, TRUE)), 0, 128), 
    23992405        (string)rc_substr($this->db->encode($this->decode_header($headers->from, TRUE)), 0, 128), 
Note: See TracChangeset for help on using the changeset viewer.