Aleksander Machniak
2012-06-26 7ab9c1775243217f3f6cb0717b1894a98303d04e
Improve performance by skipping redundant ENABLE commands
2 files modified
40 ■■■■ changed files
program/include/rcube_imap_cache.php 13 ●●●● patch | view | raw | blame | history
program/include/rcube_imap_generic.php 27 ●●●● patch | view | raw | blame | history
program/include/rcube_imap_cache.php
@@ -917,18 +917,17 @@
            return;
        }
        // NOTE: make sure the mailbox isn't selected, before
        // enabling QRESYNC and invoking SELECT
        if ($this->imap->conn->selected !== null) {
            $this->imap->conn->close();
        }
        // Enable QRESYNC
        $res = $this->imap->conn->enable($qresync ? 'QRESYNC' : 'CONDSTORE');
        if (!is_array($res)) {
        if ($res === false) {
            return;
        }
        // Close mailbox if already selected to get most recent data
        if ($this->imap->conn->selected == $mailbox) {
            $this->imap->conn->close();
        }
        // Get mailbox data (UIDVALIDITY, HIGHESTMODSEQ, counters, etc.)
        $mbox_data = $this->imap->folder_data($mailbox);
program/include/rcube_imap_generic.php
@@ -1472,14 +1472,31 @@
     */
    function enable($extension)
    {
        if (empty($extension))
        if (empty($extension)) {
            return false;
        }
        if (!$this->hasCapability('ENABLE'))
        if (!$this->hasCapability('ENABLE')) {
            return false;
        }
        if (!is_array($extension))
        if (!is_array($extension)) {
            $extension = array($extension);
        }
        if (!empty($this->extensions_enabled)) {
            // check if all extensions are already enabled
            $diff = array_diff($extension, $this->extensions_enabled);
            if (empty($diff)) {
                return $extension;
            }
            // Make sure the mailbox isn't selected, before enabling extension(s)
            if ($this->selected !== null) {
                $this->close();
            }
        }
        list($code, $response) = $this->execute('ENABLE', $extension);
@@ -1487,7 +1504,9 @@
            $response = substr($response, 10); // remove prefix "* ENABLED "
            $result   = (array) $this->tokenizeResponse($response);
            return $result;
            $this->extensions_enabled = array_unique(array_merge((array)$this->extensions_enabled, $result));
            return $this->extensions_enabled;
        }
        return false;