Branch 'roundcubemail-plugins-kolab-3.1' - 3 commits - plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Thu Feb 5 16:38:52 CET 2015
plugins/libkolab/SQL/mysql.initial.sql | 4 ++-
plugins/libkolab/SQL/mysql/2015020600.sql | 4 +++
plugins/libkolab/SQL/postgres.initial.sql | 31 ---------------------------
plugins/libkolab/config.inc.php.dist | 4 +++
plugins/libkolab/lib/kolab_storage_cache.php | 27 +++++++++++++++++++----
5 files changed, 33 insertions(+), 37 deletions(-)
New commits:
commit 42ce3ef0c4f69891c5106c535ab21634798e8a23
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Feb 5 16:15:16 2015 +0100
Update schema version string; remove outdated postgres database schema
diff --git a/plugins/libkolab/SQL/mysql.initial.sql b/plugins/libkolab/SQL/mysql.initial.sql
index f5417c0..c44a4fd 100644
--- a/plugins/libkolab/SQL/mysql.initial.sql
+++ b/plugins/libkolab/SQL/mysql.initial.sql
@@ -178,4 +178,4 @@ CREATE TABLE `kolab_cache_freebusy` (
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
-INSERT INTO `system` (`name`, `value`) VALUES ('libkolab-version', '2014021000');
+INSERT INTO `system` (`name`, `value`) VALUES ('libkolab-version', '2015020600');
diff --git a/plugins/libkolab/SQL/postgres.initial.sql b/plugins/libkolab/SQL/postgres.initial.sql
deleted file mode 100644
index e06346c..0000000
--- a/plugins/libkolab/SQL/postgres.initial.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * libkolab database schema
- *
- * @version @package_version@
- * @author Sidlyarenko Sergey
- * @licence GNU AGPL
- **/
-
-DROP TABLE IF EXISTS kolab_cache;
-
-CREATE TABLE kolab_cache (
- resource character varying(255) NOT NULL,
- type character varying(32) NOT NULL,
- msguid NUMERIC(20) NOT NULL,
- uid character varying(128) NOT NULL,
- created timestamp without time zone DEFAULT NULL,
- changed timestamp without time zone DEFAULT NULL,
- data text NOT NULL,
- xml text NOT NULL,
- dtstart timestamp without time zone,
- dtend timestamp without time zone,
- tags character varying(255) NOT NULL,
- words text NOT NULL,
- filename character varying(255) DEFAULT NULL,
- PRIMARY KEY(resource, type, msguid)
-);
-
-CREATE INDEX kolab_cache_resource_filename_idx ON kolab_cache (resource, filename);
-
-
-INSERT INTO system (name, value) VALUES ('libkolab-version', '2013041900');
commit d10017824b3d581b99600148cc0ba66acef2ca75
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Feb 5 16:35:40 2015 +0100
Small fixes for the previous patch
diff --git a/plugins/libkolab/config.inc.php.dist b/plugins/libkolab/config.inc.php.dist
index 7c37f96..f202d9b 100644
--- a/plugins/libkolab/config.inc.php.dist
+++ b/plugins/libkolab/config.inc.php.dist
@@ -7,7 +7,7 @@ $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';
+$rcmail_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 de128e1..72647fb 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -24,6 +24,8 @@
class kolab_storage_cache
{
+ const DB_DATE_FORMAT = 'Y-m-d H:i:s';
+
protected $db;
protected $imap;
protected $folder;
commit 4254e373c5b334977ebd6a7341a8608bcc515de7
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Feb 5 15:27:28 2015 +0100
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
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
);
More information about the commits
mailing list