Branch 'roundcubemail-plugins-kolab-format2-horde5' - plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Mon Jun 24 11:32:18 CEST 2013
plugins/libkolab/lib/kolab_storage_cache.php | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
New commits:
commit e82aea4ee04542f7a0c136c98f6c087d77185b32
Author: Thomas Bruederli <thomas at roundcube.net>
Date: Mon May 27 17:27:53 2013 +0200
Replace recursive calls with while loop when waiting for sync-lock (#1637)
diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index f5dbe01..4d62b4b 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -36,6 +36,7 @@ class kolab_storage_cache
private $synclock = false;
private $ready = false;
private $max_sql_packet = 1046576; // 1 MB - 2000 bytes
+ private $max_sync_lock_time = 600;
private $binary_cols = array('photo','pgppublickey','pkcs7publickey');
@@ -92,7 +93,7 @@ class kolab_storage_cache
return;
// increase time limit
- @set_time_limit(500);
+ @set_time_limit($this->max_sync_lock_time);
// lock synchronization for this folder or wait if locked
$this->_sync_lock();
@@ -646,12 +647,9 @@ class kolab_storage_cache
if (!$this->ready)
return;
- $sql_arr = $this->db->fetch_assoc($this->db->query(
- "SELECT msguid AS locked, ".$this->db->unixtimestamp('created')." AS created FROM kolab_cache ".
- "WHERE resource=? AND type=?",
- $this->resource_uri,
- 'lock'
- ));
+ $sql_query = "SELECT msguid AS locked, ".$this->db->unixtimestamp('created')." AS created FROM kolab_cache ".
+ "WHERE resource=? AND type=?";
+ $sql_arr = $this->db->fetch_assoc($this->db->query($sql_query, $this->resource_uri, 'lock'));
// abort if database is not set-up
if ($this->db->is_error()) {
@@ -661,6 +659,12 @@ class kolab_storage_cache
$this->synclock = true;
+ // wait if locked (expire locks after 10 minutes)
+ while ($sql_arr && intval($sql_arr['locked']) > 0 && $sql_arr['created'] + $this->max_sync_lock_time > time()) {
+ usleep(500000);
+ $sql_arr = $this->db->fetch_assoc($this->db->query($sql_query, $this->resource_uri, 'lock'));
+ }
+
// create lock record if not exists
if (!$sql_arr) {
$this->db->query(
@@ -671,12 +675,6 @@ class kolab_storage_cache
date('Y-m-d H:i:s')
);
}
- // wait if locked (expire locks after 10 minutes)
- else if (intval($sql_arr['locked']) > 0 && (time() - $sql_arr['created']) < 600) {
- usleep(500000);
- return $this->_sync_lock();
- }
- // set lock
else {
$this->db->query(
"UPDATE kolab_cache SET msguid=1, created=? ".
More information about the commits
mailing list