summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-02-05 14:27:28 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-02-05 15:30:13 (GMT)
commit4254e373c5b334977ebd6a7341a8608bcc515de7 (patch)
tree017b629f80cf88fb8f36bae8e424550368da59c2
parentb0be19f77fbdff9c6d800192ece1af8fcd251252 (diff)
downloadroundcubemail-plugins-kolab-4254e373c5b334977ebd6a7341a8608bcc515de7.tar.gz
Improve groupware object cache synchronization (#3933):
- store and compare the number of objects stored after last sync - use a (configurable) refresh interval and periodically force re-sync ATTENTION: requires database schema updates
-rw-r--r--plugins/libkolab/SQL/mysql.initial.sql2
-rw-r--r--plugins/libkolab/SQL/mysql/2015020600.sql4
-rw-r--r--plugins/libkolab/config.inc.php.dist4
-rw-r--r--plugins/libkolab/lib/kolab_storage_cache.php25
4 files changed, 30 insertions, 5 deletions
diff --git a/plugins/libkolab/SQL/mysql.initial.sql b/plugins/libkolab/SQL/mysql.initial.sql
index cc83ad3..f5417c0 100644
--- a/plugins/libkolab/SQL/mysql.initial.sql
+++ b/plugins/libkolab/SQL/mysql.initial.sql
@@ -15,6 +15,8 @@ CREATE TABLE `kolab_folders` (
`type` VARCHAR(32) NOT NULL,
`synclock` INT(10) NOT NULL DEFAULT '0',
`ctag` VARCHAR(40) DEFAULT NULL,
+ `changed` DATETIME DEFAULT NULL,
+ `objectcount` BIGINT DEFAULT NULL,
PRIMARY KEY(`folder_id`),
INDEX `resource_type` (`resource`, `type`)
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
diff --git a/plugins/libkolab/SQL/mysql/2015020600.sql b/plugins/libkolab/SQL/mysql/2015020600.sql
new file mode 100644
index 0000000..d9077a0
--- /dev/null
+++ b/plugins/libkolab/SQL/mysql/2015020600.sql
@@ -0,0 +1,4 @@
+-- improve cache synchronization (#3933)
+ALTER TABLE `kolab_folders`
+ ADD `changed` DATETIME DEFAULT NULL,
+ ADD `objectcount` BIGINT DEFAULT NULL;
diff --git a/plugins/libkolab/config.inc.php.dist b/plugins/libkolab/config.inc.php.dist
index 0c612a3..7c37f96 100644
--- a/plugins/libkolab/config.inc.php.dist
+++ b/plugins/libkolab/config.inc.php.dist
@@ -5,6 +5,10 @@
// Enable caching of Kolab objects in local database
$rcmail_config['kolab_cache'] = true;
+// Cache refresh interval (default is 12 hours)
+// after this period, cache is forced to synchronize with IMAP
+$config['kolab_cache_refresh'] = '12h';
+
// Specify format version to write Kolab objects (must be a string value!)
$rcmail_config['kolab_format_version'] = '3.0';
diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index b31cd74..de128e1 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -38,6 +38,7 @@ class kolab_storage_cache
protected $synclock = false;
protected $ready = false;
protected $cache_table;
+ protected $cache_refresh = 3600;
protected $folders_table;
protected $max_sql_packet;
protected $max_sync_lock_time = 600;
@@ -79,6 +80,7 @@ class kolab_storage_cache
$this->imap = $rcmail->get_storage();
$this->enabled = $rcmail->config->get('kolab_cache', false);
$this->folders_table = $this->db->table_name('kolab_folders');
+ $this->cache_refresh = get_offset_sec($rcmail->config->get('kolab_cache_refresh', '12h'));
if ($this->enabled) {
// always read folder cache and lock state from DB master
@@ -172,8 +174,14 @@ class kolab_storage_cache
// read cached folder metadata
$this->_read_folder_data();
- // check cache status hash first ($this->metadata is set in _read_folder_data())
- if ($this->metadata['ctag'] != $this->folder->get_ctag()) {
+ // check cache status ($this->metadata is set in _read_folder_data())
+ if ( empty($this->metadata['ctag']) ||
+ empty($this->metadata['changed']) ||
+ $this->metadata['objectcount'] === null ||
+ $this->metadata['changed'] < date(self::DB_DATE_FORMAT, time() - $this->cache_refresh) ||
+ $this->metadata['ctag'] != $this->folder->get_ctag() ||
+ intval($this->metadata['objectcount']) !== $this->count()
+ ) {
// lock synchronization for this folder or wait if locked
$this->_sync_lock();
@@ -221,6 +229,9 @@ class kolab_storage_cache
// update ctag value (will be written to database in _sync_unlock())
$this->metadata['ctag'] = $this->folder->get_ctag();
+ $this->metadata['changed'] = date(self::DB_DATE_FORMAT, time());
+ // remember the number of cache entries linked to this folder
+ $this->metadata['objectcount'] = $this->count();
}
$this->bypass(false);
@@ -723,7 +734,7 @@ class kolab_storage_cache
$sql_data = array('changed' => null, 'xml' => '', 'tags' => '', 'words' => '');
if ($object['changed']) {
- $sql_data['changed'] = date('Y-m-d H:i:s', is_object($object['changed']) ? $object['changed']->format('U') : $object['changed']);
+ $sql_data['changed'] = date(self::DB_DATE_FORMAT, is_object($object['changed']) ? $object['changed']->format('U') : $object['changed']);
}
if ($object['_formatobj']) {
@@ -876,7 +887,9 @@ class kolab_storage_cache
if (!empty($this->folder_id))
return;
- $sql_arr = $this->db->fetch_assoc($this->db->query("SELECT folder_id, synclock, ctag FROM $this->folders_table WHERE resource=?", $this->resource_uri));
+ $sql_arr = $this->db->fetch_assoc($this->db->query("SELECT folder_id, synclock, ctag, changed, objectcount"
+ . " FROM $this->folders_table WHERE resource=?", $this->resource_uri));
+
if ($sql_arr) {
$this->metadata = $sql_arr;
$this->folder_id = $sql_arr['folder_id'];
@@ -927,8 +940,10 @@ class kolab_storage_cache
return;
$this->db->query(
- "UPDATE $this->folders_table SET synclock = 0, ctag = ? WHERE folder_id = ?",
+ "UPDATE $this->folders_table SET synclock = 0, ctag = ?, changed = ?, objectcount = ? WHERE folder_id = ?",
$this->metadata['ctag'],
+ $this->metadata['changed'],
+ $this->metadata['objectcount'],
$this->folder_id
);