2 commits - plugins/calendar plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Tue Nov 4 13:09:00 CET 2014


 plugins/calendar/calendar.php                |   10 ++++++++--
 plugins/libkolab/lib/kolab_storage_cache.php |   22 ++++++++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)

New commits:
commit 8627b72357582bf418fd41e2fec68d5c7cfce81d
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Tue Nov 4 13:04:57 2014 +0100

    Avoid hitting executing time limit when synchronizing cache (#3677):
    This change will make the synchronization process abort before the time limit is reached.
    The folder is not flagged as fully synchronized and subsequent requests will continue the synchronization.
    Application scripts can read the public 'sync_complete' property and initiate a next sync request.

diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php
index bced3b3..89f650d 100644
--- a/plugins/libkolab/lib/kolab_storage_cache.php
+++ b/plugins/libkolab/lib/kolab_storage_cache.php
@@ -26,6 +26,8 @@ class kolab_storage_cache
 {
     const DB_DATE_FORMAT = 'Y-m-d H:i:s';
 
+    public $sync_complete = false;
+
     protected $db;
     protected $imap;
     protected $folder;
@@ -158,7 +160,14 @@ class kolab_storage_cache
             return;
 
         // increase time limit
-        @set_time_limit($this->max_sync_lock_time);
+        @set_time_limit($this->max_sync_lock_time - 60);
+
+        // get effective time limit we have for synchronization (~70% of the execution time)
+        $time_limit = ini_get('max_execution_time') * 0.7;
+        $sync_start = time();
+
+        // assume sync will be completed
+        $this->sync_complete = true;
 
         if (!$this->ready) {
             // kolab cache is disabled, synchronize IMAP mailbox cache only
@@ -199,9 +208,16 @@ class kolab_storage_cache
                     }
 
                     // fetch new objects from imap
+                    $i = 0;
                     foreach (array_diff($imap_index, $old_index) as $msguid) {
                         if ($object = $this->folder->read_object($msguid, '*')) {
                             $this->_extended_insert($msguid, $object);
+
+                            // check time limit and abort sync if running too long
+                            if (++$i % 50 == 0 && time() - $sync_start > $time_limit) {
+                                $this->sync_complete = false;
+                                break;
+                            }
                         }
                     }
                     $this->_extended_insert(0, null);
@@ -217,7 +233,9 @@ class kolab_storage_cache
                     }
 
                     // update ctag value (will be written to database in _sync_unlock())
-                    $this->metadata['ctag'] = $this->folder->get_ctag();
+                    if ($this->sync_complete) {
+                        $this->metadata['ctag'] = $this->folder->get_ctag();
+                    }
                 }
 
                 $this->bypass(false);


commit 35f7ec0ec96e6dd98b5245d1178a03e896a500b5
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Tue Nov 4 12:45:37 2014 +0100

    Add more query parameters for generating random data

diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index 1366141..9b815bc 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -1675,17 +1675,23 @@ class calendar extends rcube_plugin
 
   /**
    * TEMPORARY: generate random event data for testing
-   * Create events by opening http://<roundcubeurl>/?_task=calendar&_action=randomdata&_num=500
+   * Create events by opening http://<roundcubeurl>/?_task=calendar&_action=randomdata&_num=500&_date=2014-08-01&_dev=120
    */
   public function generate_randomdata()
   {
+    @set_time_limit(0);
+
     $num   = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
+    $date  = $_REQUEST['_date'] ?: 'now';
+    $dev   = $_REQUEST['_dev'] ?: 30;
     $cats  = array_keys($this->driver->list_categories());
     $cals  = $this->driver->list_calendars(true);
     $count = 0;
 
     while ($count++ < $num) {
-      $start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
+      $spread = intval($dev) * 86400; // days
+      $refdate = strtotime($date);
+      $start = round(($refdate + rand(-$spread, $spread)) / 600) * 600;
       $duration = round(rand(30, 360) / 30) * 30 * 60;
       $allday = rand(0,20) > 18;
       $alarm = rand(-30,12) * 5;




More information about the commits mailing list