Aleksander Machniak
2015-05-12 b1e35a685c7d02242ad171953614434c7474d051
Performance: Improve changes detection, so we update index only if needed
2 files modified
38 ■■■■■ changed files
program/lib/Roundcube/rcube_cache.php 19 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_cache_shared.php 19 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_cache.php
@@ -43,6 +43,7 @@
    private $packed;
    private $index;
    private $debug;
    private $index_changed = false;
    private $cache         = array();
    private $cache_changes = array();
    private $cache_sums    = array();
@@ -118,7 +119,6 @@
    function set($key, $data)
    {
        $this->cache[$key]         = $data;
        $this->cache_changed       = true;
        $this->cache_changes[$key] = true;
    }
@@ -167,7 +167,6 @@
        // Remove all keys
        if ($key === null) {
            $this->cache         = array();
            $this->cache_changed = false;
            $this->cache_changes = array();
            $this->cache_sums    = array();
        }
@@ -227,10 +226,6 @@
     */
    function close()
    {
        if (!$this->cache_changed) {
            return;
        }
        foreach ($this->cache as $key => $data) {
            // The key has been used
            if ($this->cache_changes[$key]) {
@@ -244,7 +239,9 @@
            }
        }
        $this->write_index();
        if ($this->index_changed) {
            $this->write_index();
        }
    }
@@ -486,6 +483,10 @@
            }
        }
        if ($result) {
            $this->index_changed = true;
        }
        return $result;
    }
@@ -513,6 +514,10 @@
            }
        }
        if ($result) {
            $this->index_changed = true;
        }
        if ($index) {
            if (($idx = array_search($key, $this->index)) !== false) {
                unset($this->index[$idx]);
program/lib/Roundcube/rcube_cache_shared.php
@@ -42,6 +42,7 @@
    private $index;
    private $table;
    private $debug;
    private $index_changed = false;
    private $cache         = array();
    private $cache_changes = array();
    private $cache_sums    = array();
@@ -115,7 +116,6 @@
    function set($key, $data)
    {
        $this->cache[$key]         = $data;
        $this->cache_changed       = true;
        $this->cache_changes[$key] = true;
    }
@@ -164,7 +164,6 @@
        // Remove all keys
        if ($key === null) {
            $this->cache         = array();
            $this->cache_changed = false;
            $this->cache_changes = array();
            $this->cache_sums    = array();
        }
@@ -222,10 +221,6 @@
     */
    function close()
    {
        if (!$this->cache_changed) {
            return;
        }
        foreach ($this->cache as $key => $data) {
            // The key has been used
            if ($this->cache_changes[$key]) {
@@ -239,7 +234,9 @@
            }
        }
        $this->write_index();
        if ($this->index_changed) {
            $this->write_index();
        }
    }
@@ -474,6 +471,10 @@
            }
        }
        if ($result) {
            $this->index_changed = true;
        }
        return $result;
    }
@@ -501,6 +502,10 @@
            }
        }
        if ($result) {
            $this->index_changed = true;
        }
        if ($index) {
            if (($idx = array_search($key, $this->index)) !== false) {
                unset($this->index[$idx]);