alecpl
2008-04-29 257782150db70dbe852d1c71fe6fd8abda0229f0
- improved messages list performance - patch from Justin Heesemann


4 files modified
67 ■■■■■ changed files
CHANGELOG 4 ●●●● patch | view | raw | blame | history
program/include/main.inc 17 ●●●● patch | view | raw | blame | history
program/include/rcube_imap.php 41 ●●●● patch | view | raw | blame | history
program/include/rcube_shared.inc 5 ●●●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,10 @@
CHANGELOG RoundCube Webmail
---------------------------
2008/04/29 (alec)
----------
- improved messages list performance - patch from Justin Heesemann
2008/04/23 (alec)
----------
- Append skin_path to images location only when it starts 
program/include/main.inc
@@ -1060,8 +1060,15 @@
function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE)
  {
  global $OUTPUT_TYPE, $OUTPUT;
  static $html_encode_arr, $js_rep_table, $xml_rep_table;
  static $html_encode_arr = false;
  static $js_rep_table = false;
  static $xml_rep_table = false;
  $charset = $OUTPUT->get_charset();
  $is_iso_8859_1 = false;
  if ($charset == 'ISO-8859-1') {
    $is_iso_8859_1 = true;
  }
  if (!$enctype)
    $enctype = $GLOBALS['OUTPUT_TYPE'];
@@ -1102,7 +1109,7 @@
    return rawurlencode($str);
  // if the replace tables for XML and JS are not yet defined
  if (!$js_rep_table)
  if ($js_rep_table===false)
    {
    $js_rep_table = $xml_rep_table = array();
    $xml_rep_table['&'] = '&';
@@ -1111,7 +1118,7 @@
      {
      $xml_rep_table[Chr($c)] = "&#$c;";
      
      if ($OUTPUT->get_charset()=='ISO-8859-1')
      if ($is_iso_8859_1)
        $js_rep_table[Chr($c)] = sprintf("\\u%04x", $c);
      }
@@ -1125,8 +1132,8 @@
  // encode for javascript use
  if ($enctype=='js')
    {
    if ($OUTPUT->get_charset()!='UTF-8')
      $str = rcube_charset_convert($str, RCMAIL_CHARSET, $OUTPUT->get_charset());
    if ($charset!='UTF-8')
      $str = rcube_charset_convert($str, RCMAIL_CHARSET,$charset);
      
    return preg_replace(array("/\r?\n/", "/\r/", '/<\\//'), array('\n', '\n', '<\\/'), addslashes(strtr($str, $js_rep_table)));
    }
program/include/rcube_imap.php
@@ -574,27 +574,24 @@
      // retrieve headers from IMAP
      if ($this->get_capability('sort') && ($msg_index = iil_C_Sort($this->conn, $mailbox, $this->sort_field, $this->skip_deleted ? 'UNDELETED' : '')))
        {        
        $msgs = $msg_index[$begin];
        for ($i=$begin+1; $i < $end; $i++)
          $msgs = $msgs.','.$msg_index[$i];
        $mymsgidx = array_slice ($msg_index, $begin, $end-$begin, true);
        $msgs = join(",", $mymsgidx);
        $headers_sorted = true;
        }
      else
        {
        $msgs = sprintf("%d:%d", $begin+1, $end);
        $i = 0;
        for ($msg_seqnum = $begin; $msg_seqnum <= $end; $msg_seqnum++)
          $msg_index[$i++] = $msg_seqnum;
        $msg_index = range($begin, $end);
        }
      // use this class for message sorting
      $sorter = new rcube_header_sorter();
      $sorter->set_sequence_numbers($msg_index);
      // fetch reuested headers from server
      $a_msg_headers = array();
      $deleted_count = $this->_fetch_headers($mailbox, $msgs, $a_msg_headers, $cache_key);
      if ($this->sort_order == 'DESC' && $headers_sorted) {
        //since the sort order is not used in the iil_c_sort function we have to do it here
        $a_msg_headers = array_reverse($a_msg_headers);
      }
      // delete cached messages with a higher index than $max+1
      // Changed $max to $max+1 to fix this bug : #1484295
      $this->clear_message_cache($cache_key, $max + 1);
@@ -607,13 +604,16 @@
    // return empty array if no messages found
    if (!is_array($a_msg_headers) || empty($a_msg_headers))
        return array();
    if (!is_array($a_msg_headers) || empty($a_msg_headers)) {
      return array();
    }
    // if not already sorted
    if (!$headers_sorted)
      {
      // use this class for message sorting
      $sorter = new rcube_header_sorter();
      $sorter->set_sequence_numbers($msg_index);
      $sorter->sort_headers($a_msg_headers);
      if ($this->sort_order == 'DESC')
@@ -652,16 +652,19 @@
   */
  function _list_header_set($mailbox, $msgs, $page=NULL, $sort_field=NULL, $sort_order=NULL)
    {
    // also accept a comma-separated list of message ids
    if (is_string($msgs))
      $msgs = split(',', $msgs);
    if (!strlen($mailbox) || empty($msgs))
      return array();
    // also accept a comma-separated list of message ids
    if (is_array ($msgs)) {
      $max = count ($msgs);
      $msgs = join (',', $msgs);
    } else {
      $max = count(split(',', $msgs));
    }
    $this->_set_sort_order($sort_field, $sort_order);
    $max = count($msgs);
    $start_msg = ($this->list_page-1) * $this->page_size;
    // fetch reuested headers from server
program/include/rcube_shared.inc
@@ -92,7 +92,8 @@
function rcube_label($attrib)
{
  global $sess_user_lang, $OUTPUT;
  static $sa_text_data, $s_language, $utf8_decode;
  static $sa_text_data = false;
  static $s_language, $utf8_decode;
  // extract attributes
  if (is_string($attrib))
@@ -106,7 +107,7 @@
  // load localized texts
  if (!$sa_text_data || $s_language != $sess_user_lang)
  if ($sa_text_data===false || $s_language != $sess_user_lang)
    {
    $sa_text_data = array();