Changeset 710e274 in github


Ignore:
Timestamp:
Oct 20, 2010 9:33:27 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
659cf14c
Parents:
8794f16
Message:
  • Improve performance of unseen messages counting, use STATUS instead of SELECT+SEARCH (#1487058)
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r8794f16 r710e274  
    3838- Fix decoding of e-mail address strings in message headers (#1487068) 
    3939- Fix handling of attachments when Content-Disposition is not inline nor attachment (#1487051) 
     40- Improve performance of unseen messages counting (#1487058) 
    4041 
    4142RELEASE 0.4.2 
  • program/include/rcube_imap_generic.php

    ra2e8cb36 r710e274  
    734734    } 
    735735 
     736    /** 
     737     * Executes STATUS comand 
     738     * 
     739     * @param string $mailbox Mailbox name 
     740     * @param array  $items   Requested item names 
     741     * 
     742     * @return array Status item-value hash 
     743     * @access public 
     744     * @since 0.5-beta 
     745     */ 
     746    function status($mailbox, $items) 
     747    { 
     748            if (empty($mailbox) || empty($items)) { 
     749                    return false; 
     750            } 
     751 
     752        list($code, $response) = $this->execute('STATUS', array($this->escape($mailbox), 
     753            '(' . implode(' ', (array) $items) . ')')); 
     754 
     755        if ($code == self::ERROR_OK && preg_match('/\* STATUS /i', $response)) { 
     756            $result   = array(); 
     757            $response = substr($response, 9); // remove prefix "* STATUS " 
     758 
     759            list($mbox, $items) = $this->tokenizeResponse($response, 2); 
     760 
     761            for ($i=0, $len=count($items); $i<$len; $i += 2) { 
     762                $result[$items[$i]] = (int) $items[$i+1]; 
     763            } 
     764 
     765                        return $result; 
     766                } 
     767 
     768        return false; 
     769    } 
     770 
    736771    function checkForRecent($mailbox) 
    737772    { 
     
    758793                    return $this->data['EXISTS']; 
    759794            } 
     795 
     796        return false; 
     797    } 
     798 
     799    /** 
     800     * Returns count of messages without \Seen flag in a specified folder 
     801     * 
     802     * @param string $mailbox Mailbox name 
     803     * 
     804     * @return int Number of messages, False on error 
     805     * @access public 
     806     */ 
     807    function countUnseen($mailbox) 
     808    { 
     809        // Try STATUS, should be faster 
     810        $counts = $this->status($mailbox, array('UNSEEN')); 
     811        if (is_array($counts)) { 
     812            return (int) $counts['UNSEEN']; 
     813        } 
     814 
     815        // Invoke SEARCH as a fallback 
     816        // @TODO: ESEARCH support 
     817        $index = $this->search($mailbox, 'ALL UNSEEN'); 
     818        if (is_array($index)) { 
     819            return count($index); 
     820        } 
    760821 
    761822        return false; 
     
    14141475    } 
    14151476 
    1416     function countUnseen($folder) 
    1417     { 
    1418         $index = $this->search($folder, 'ALL UNSEEN'); 
    1419         if (is_array($index)) 
    1420             return count($index); 
    1421         return false; 
    1422     } 
    1423  
    14241477    // Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about 
    14251478    // 7 times instead :-) See comments on http://uk2.php.net/references and this article: 
Note: See TracChangeset for help on using the changeset viewer.