alecpl
2008-04-11 6d2714b3b3660f8a4efbb9c53e00b76245c2bcc2
#1484972: optimization: mark as read in one action with preview, deleted redundant quota reads


1 files deleted
6 files modified
124 ■■■■ changed files
index.php 4 ●●●● patch | view | raw | blame | history
program/js/app.js 39 ●●●● patch | view | raw | blame | history
program/steps/mail/check_recent.inc 2 ●●● patch | view | raw | blame | history
program/steps/mail/func.inc 31 ●●●● patch | view | raw | blame | history
program/steps/mail/move_del.inc 2 ●●● patch | view | raw | blame | history
program/steps/mail/quotadisplay.inc 28 ●●●●● patch | view | raw | blame | history
program/steps/mail/show.inc 18 ●●●● patch | view | raw | blame | history
index.php
@@ -326,10 +326,6 @@
  if ($_action=='rss')
    include('program/steps/mail/rss.inc');
    
  if ($_action=='quotadisplay')
    include('program/steps/mail/quotadisplay.inc');
  // make sure the message count is refreshed
  $IMAP->messagecount($_SESSION['mbox'], 'ALL', TRUE);
}
program/js/app.js
@@ -179,7 +179,6 @@
          {
          this.enable_command('compose', 'add-contact', false);
          parent.rcmail.show_contentframe(true);
          parent.rcmail.mark_message('read', this.env.uid);
          }
        if ((this.env.action=='show' || this.env.action=='preview') && this.env.blockedobjects)
@@ -1569,6 +1568,28 @@
    this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
  };
  // set class to read/unread
  this.mark_as_read_from_preview = function(uid)
  {
    var icn_src;
    var rows = parent.rcmail.message_list.rows;
    if(rows[uid].unread)
      {
        rows[uid].unread = false;
        rows[uid].classname = rows[uid].classname.replace(/\s*unread/, '');
        parent.rcmail.set_classname(rows[uid].obj, 'unread', false);
        if (rows[uid].replied && parent.rcmail.env.repliedicon)
          icn_src = parent.rcmail.env.repliedicon;
        else if (parent.rcmail.env.messageicon)
          icn_src = parent.rcmail.env.messageicon;
    if (rows[uid].icon && icn_src)
          rows[uid].icon.src = icn_src;
      }
  }
  
  // mark all message rows as deleted/undeleted
  this.toggle_delete_status = function(a_uids)
@@ -3254,15 +3275,12 @@
    this.set_page_buttons();
    };
  // replace content of quota display
  this.set_quota = function()
  this.set_quota = function(content)
    {
    if (this.gui_objects.quotadisplay &&
        this.gui_objects.quotadisplay.attributes.getNamedItem('display') &&
        this.gui_objects.quotadisplay.attributes.getNamedItem('id'))
      this.http_request('quotadisplay', '_display='+
      this.gui_objects.quotadisplay.attributes.getNamedItem('display').nodeValue+
      '&_id='+this.gui_objects.quotadisplay.attributes.getNamedItem('id').nodeValue, false);
    if (this.gui_objects.quotadisplay && content)
      this.gui_objects.quotadisplay.innerHTML = content;
     };
@@ -3308,6 +3326,11 @@
      }
    };
  // update parent's mailboxlist (from preview)
  this.set_unread_count_from_preview = function(mbox, count, set_title)
  {
    parent.rcmail.set_unread_count(mbox, count, set_title);
  }
  // add row to contacts list
  this.add_contact_row = function(cid, cols, select)
program/steps/mail/check_recent.inc
@@ -37,7 +37,7 @@
      $OUTPUT->set_env('messagecount', $IMAP->messagecount());
      $OUTPUT->command('set_unread_count', $mbox_name, $unread_count, ($mbox_name == 'INBOX'));
      $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text());
      $OUTPUT->command('set_quota', $IMAP->get_quota());
      $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
      // add new message headers to list
      $a_headers = array();
program/steps/mail/func.inc
@@ -408,30 +408,43 @@
  if (!$attrib['id'])
    $attrib['id'] = 'rcmquotadisplay';
  if(isset($attrib['display']))
    $_SESSION['quota_display'] = $attrib['display'];
  $OUTPUT->add_gui_object('quotadisplay', $attrib['id']);
  // allow the following attributes to be added to the <span> tag
  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'display'));
  $out = '<span' . $attrib_str . '>';
  $out .= rcmail_quota_content($attrib['display']);
  $out .= rcmail_quota_content();
  $out .= '</span>';
  return $out;
  }
function rcmail_quota_content($display)
function rcmail_quota_content($quota=NULL)
  {
  global $IMAP, $COMM_PATH;
  if (!$IMAP->get_capability('QUOTA'))
    $quota_text = rcube_label('unknown');
  else if ($quota = $IMAP->get_quota())
  $display = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : '';
  if (is_array($quota) && !empty($quota['used']) && !empty($quota['total']))
    {
    $quota_text = sprintf("%s / %s (%.0f%%)",
                          show_bytes($quota["used"] * 1024),
                          show_bytes($quota["total"] * 1024),
                          $quota["percent"]);
      if (!isset($quota['percent']))
        $quota['percent'] = $quota['used'] / $quota['total'];
    }
  elseif (!$IMAP->get_capability('QUOTA'))
    return rcube_label('unknown');
  else
    $quota = $IMAP->get_quota();
  if ($quota)
    {
    $quota_text = sprintf('%s / %s (%.0f%%)',
                          show_bytes($quota['used'] * 1024),
                          show_bytes($quota['total'] * 1024),
                          $quota['percent']);
    // show quota as image (by Brett Patterson)
    if ($display == 'image' && function_exists('imagegif'))
program/steps/mail/move_del.inc
@@ -92,7 +92,7 @@
if ($_action=='moveto' && $target)
  $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN'));
$OUTPUT->command('set_quota', $IMAP->get_quota());
$OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));
// add new rows from next page (if any)
if ($_POST['_from']!='show' && ($jump_back || $nextpage_count > 0))
program/steps/mail/quotadisplay.inc
File was deleted
program/steps/mail/show.inc
@@ -53,8 +53,10 @@
  else if ($_SESSION['safe_messages'][$MESSAGE['UID']])
    $MESSAGE['is_safe'] = 1;
  $mbox_name = $IMAP->get_mailbox_name();
  // calculate Etag for this request
  $etag = md5($MESSAGE['UID'].$IMAP->get_mailbox_name().session_id().intval($MESSAGE['headers']->mdn_sent).intval($MESSAGE['is_safe']).intval($PRINT_MODE));
  $etag = md5($MESSAGE['UID'].$mbox_name.session_id().intval($MESSAGE['headers']->mdn_sent).intval($MESSAGE['is_safe']).intval($PRINT_MODE));
  // allow caching, unless remote images are present
  if ((bool)$MESSAGE['is_safe'])
@@ -75,17 +77,23 @@
  else
    $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
  // mark message as read
  if (!$MESSAGE['headers']->seen && $_action != 'preview')
    $IMAP->set_flag($MESSAGE['UID'], 'SEEN');
  if (!$MESSAGE['headers']->seen)
    {
      $marked = $IMAP->set_flag($MESSAGE['UID'], 'SEEN');
      if($_action == 'preview' && $marked != -1)
    {
    $OUTPUT->command('set_unread_count_from_preview', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN'), ($mbox_name == 'INBOX'));
    $OUTPUT->command('mark_as_read_from_preview', $MESSAGE['UID']);
    }
    }
  // give message uid to the client
  $OUTPUT->set_env('uid', $MESSAGE['UID']);
  $OUTPUT->set_env('safemode', $MESSAGE['is_safe']);
  
  // check for unset disposition notification
  if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent && $IMAP->get_mailbox_name() != $CONFIG['drafts_mbox'])
  if ($MESSAGE['headers']->mdn_to && !$MESSAGE['headers']->mdn_sent && $mbox_name != $CONFIG['drafts_mbox'])
  {
    if (intval($CONFIG['mdn_requests']) === 1)
    {