From b1e35a685c7d02242ad171953614434c7474d051 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 12 May 2015 14:33:02 -0400
Subject: [PATCH] Performance: Improve changes detection, so we update index only if needed
---
program/lib/Roundcube/rcube_cache.php | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/program/lib/Roundcube/rcube_cache.php b/program/lib/Roundcube/rcube_cache.php
index dffb600..41f7b33 100644
--- a/program/lib/Roundcube/rcube_cache.php
+++ b/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]);
--
Gitblit v1.9.1