Changeset 2673 in subversion


Ignore:
Timestamp:
Jun 22, 2009 2:32:51 PM (4 years ago)
Author:
alec
Message:
  • performance improvements of messages caching
Location:
trunk/roundcubemail/program/include
Files:
2 edited

Legend:

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

    r2672 r2673  
    864864 
    865865    // fetch complete message index 
    866     $msg_count = $this->_messagecount($mailbox); 
    867866    if ($this->get_capability('sort') && ($a_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : ''))) 
    868867      { 
     
    874873    else 
    875874      { 
    876       $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:$msg_count", $this->sort_field, $this->skip_deleted); 
     875      $a_index = iil_C_FetchHeaderIndex($this->conn, $mailbox, "1:*", $this->sort_field, $this->skip_deleted); 
    877876 
    878877      if ($this->sort_order=="ASC") 
     
    920919      if (isset($cache_index[$id])) 
    921920        { 
    922         $this->remove_message_cache($cache_key, $cache_index[$id]); 
     921        $for_remove[] = $cache_index[$id]; 
    923922        unset($cache_index[$id]); 
    924923        } 
    925924         
    926         $toupdate[] = $id; 
    927       } 
     925        $for_update[] = $id; 
     926      } 
     927 
     928    // clear messages at wrong positions and those deleted that are still in cache_index       
     929    if (!empty($for_remove)) 
     930      $cache_index = array_merge($cache_index, $for_remove); 
     931     
     932    if (!empty($cache_index)) 
     933      $this->remove_message_cache($cache_key, $cache_index); 
    928934 
    929935    // fetch complete headers and add to cache 
    930     if (!empty($toupdate)) { 
    931       if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $toupdate), false, $this->fetch_add_headers)) 
     936    if (!empty($for_update)) { 
     937      if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $for_update), false, $this->fetch_add_headers)) 
    932938        foreach ($headers as $header) 
    933939          $this->add_message_cache($cache_key, $header->id, $header); 
    934       } 
    935      
    936     // those ids that are still in cache_index have been deleted       
    937     if (!empty($cache_index)) 
    938       { 
    939       foreach ($cache_index as $id => $uid) 
    940         $this->remove_message_cache($cache_key, $uid); 
    941940      } 
    942941    } 
     
    15501549    if ($this->caching_enabled) 
    15511550      { 
    1552       foreach ($uids as $uid) 
    1553         if ($cached_headers = $this->get_cached_message($cache_key, $uid)) 
    1554           $this->remove_message_cache($cache_key, $uid); 
     1551      $this->remove_message_cache($cache_key, $uids); 
    15551552 
    15561553      // close and re-open connection 
     
    16611658 
    16621659      // clear cache from the lowest index on 
    1663       $this->clear_message_cache($cache_key, $start_index); 
     1660      if ($start_index < 100000) 
     1661        $this->clear_message_cache($cache_key, $start_index); 
    16641662      } 
    16651663 
     
    17161714 
    17171715      // clear cache from the lowest index on 
    1718       $this->clear_message_cache($cache_key, $start_index); 
     1716      if ($start_index < 100000) 
     1717        $this->clear_message_cache($cache_key, $start_index); 
    17191718      } 
    17201719 
     
    23262325        $key, 
    23272326        $uid); 
    2328  
    23292327      if ($sql_arr = $this->db->fetch_assoc($sql_result)) 
    23302328        { 
     
    24332431   * @access private 
    24342432   */ 
    2435   function remove_message_cache($key, $uid) 
     2433  function remove_message_cache($key, $uids) 
    24362434    { 
    24372435    if (!$this->caching_enabled) 
     
    24402438    $this->db->query( 
    24412439      "DELETE FROM ".get_table_name('messages')." 
    2442        WHERE  user_id=? 
    2443        AND    cache_key=? 
    2444        AND    uid=?", 
     2440      WHERE  user_id=? 
     2441      AND    cache_key=? 
     2442      AND    uid IN (".$this->db->array2list($uids, 'integer').")", 
    24452443      $_SESSION['user_id'], 
    2446       $key, 
    2447       $uid); 
     2444      $key); 
    24482445    } 
    24492446 
  • trunk/roundcubemail/program/include/rcube_mdb2.php

    r2463 r2673  
    471471 
    472472  /** 
     473   * Return list of elements for use with SQL's IN clause 
     474   * 
     475   * @param  string Input array 
     476   * @return string Elements list string 
     477   * @access public 
     478   */ 
     479  function array2list($arr, $type=null) 
     480    { 
     481    if (!is_array($arr)) 
     482      return $this->quote($arr, $type); 
     483     
     484    $res = array(); 
     485    foreach ($arr as $item) 
     486      $res[] = $this->quote($item, $type); 
     487 
     488    return implode(',', $res); 
     489    } 
     490 
     491 
     492  /** 
    473493   * Return SQL statement to convert a field value into a unix timestamp 
    474494   * 
Note: See TracChangeset for help on using the changeset viewer.