View Issue Details

IDProjectCategoryView StatusLast Update
0013578Tine 2.0CalDAVpublic2017-11-03 11:43
ReporteringoratsdorfAssigned Toingoratsdorf 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformi386OSlinuxOS Version3.2.0-24
Product Versiongit master 
Target Version2017.08.9 Community EditionFixed in Version2017.08.9 Community Edition 
Summary0013578: Reinstate CalDAV default time-range filter to avoid memory issues
DescriptionBy default, if no filter is set, CalDAV returns ALL children of a collection, which could be several thousands.
The attached patch adds another time-range default filter that only returns children within the config defined _getMaxPeriodFrom months and up to 4 years into the future.
Tagscaldav
mwticket

Activities

ingoratsdorf

ingoratsdorf

2017-10-23 01:08

developer  

Reinstate time-range default filters.patch (3,936 bytes)
From d04e05cfdfbb93aa77f57df89341520d42c77205 Mon Sep 17 00:00:00 2001
From: Ingo Ratsdorf <ingo@envirology.co.nz>
Date: Sat, 18 Feb 2017 07:52:29 +1300
Subject: [PATCH] Reinstating time-range default filters

Reinstating time-range default filters to prevent memory and time overrus for too large calendars
Both EmClient and CalDAVSync would take forever otherwise
---
 tine20/Calendar/Frontend/WebDAV/Container.php | 36 ++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/tine20/Calendar/Frontend/WebDAV/Container.php b/tine20/Calendar/Frontend/WebDAV/Container.php
index 4ec69248f2..57a96be2e7 100644
--- a/tine20/Calendar/Frontend/WebDAV/Container.php
+++ b/tine20/Calendar/Frontend/WebDAV/Container.php
@@ -118,6 +118,18 @@ class Calendar_Frontend_WebDAV_Container extends Tinebase_WebDav_Container_Abstr
                     'field'     => 'container_id',
                     'operator'  => 'equals',
                     'value'     => $this->_container->getId()
+                ),
+                /** This is really needed to prevent memory overruns and not to return all calendar events of all times
+                  * IF there are no filters defined
+                  * It could be handled more elegantly by using user (config) defined time ranges
+                **/
+                array(
+                    'field'    => 'period',
+                    'operator'  => 'within',
+                    'value'     => array(
+                        'from'  => Tinebase_DateTime::now()->subMonth($this->_getMaxPeriodFrom()),
+                        'until' => Tinebase_DateTime::now()->addYear(4)
+                    )
                 )
             ));
 
@@ -304,7 +316,7 @@ class Calendar_Frontend_WebDAV_Container extends Tinebase_WebDav_Container_Abstr
                 $periodFrom = Tinebase_DateTime::now()->subMonth($this->_getMaxPeriodFrom());
             }
             if ($periodUntil === null) {
-                $periodUntil = Tinebase_DateTime::now()->addYear(1000);
+                $periodUntil = Tinebase_DateTime::now()->addYear(4);
             }
 
             $filterArray[] = array(
@@ -324,17 +336,29 @@ class Calendar_Frontend_WebDAV_Container extends Tinebase_WebDav_Container_Abstr
         
         return array_keys($this->_calendarQueryCache);
     }
-    
+
     /**
-     * get max period (from) in months (default: 12000)
-     * 
+     * get max period (from) in months (default: 2)
+     *
      * @return integer
      */
     protected function _getMaxPeriodFrom()
     {
-        return Calendar_Config::getInstance()->get(Calendar_Config::MAX_FILTER_PERIOD_CALDAV, 12000);
+        // if the client does support sync tokens and the plugin Tinebase_WebDav_Plugin_SyncToken is active
+        if ((Tinebase_Config::getInstance()->get(Tinebase_Config::WEBDAV_SYNCTOKEN_ENABLED))  && (Calendar_Convert_Event_VCalendar_Factory::supportsSyncToken($_SERVER['HTTP_USER_AGENT']))) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
+                Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' SyncTokenSupport enabled');
+            $result = Calendar_Config::getInstance()->get(Calendar_Config::MAX_FILTER_PERIOD_CALDAV_SYNCTOKEN, 100);
+            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
+                Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .
+                    ' SyncToken active: allow to filter for all calendar events => return ' . $result . ' months');
+            return $result;
+        }
+        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG))
+            Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' SyncTokenSupport disabled or client does not support it');
+        return Calendar_Config::getInstance()->get(Calendar_Config::MAX_FILTER_PERIOD_CALDAV, 2);
     }
-    
+
     /**
      * (non-PHPdoc)
      *
-- 
2.11.1.windows.1

ingoratsdorf

ingoratsdorf

2017-10-28 08:02

developer   ~0021048

Created https://github.com/tine20/Tine-2.0-Open-Source-Groupware-and-CRM/pull/33

Issue History

Date Modified Username Field Change
2017-10-23 01:08 ingoratsdorf New Issue
2017-10-23 01:08 ingoratsdorf File Added: Reinstate time-range default filters.patch
2017-10-23 01:08 ingoratsdorf Tag Attached: caldav
2017-10-28 08:02 ingoratsdorf Note Added: 0021048
2017-10-28 08:13 ingoratsdorf Assigned To => ingoratsdorf
2017-10-28 08:13 ingoratsdorf Status new => assigned
2017-11-03 11:05 pschuele Summary Reinstale CalDAV default time-range filter to avoid memory issues => Reinstate CalDAV default time-range filter to avoid memory issues
2017-11-03 11:42 pschuele Target Version => 2017.08.9 Community Edition
2017-11-03 11:43 pschuele Status assigned => resolved
2017-11-03 11:43 pschuele Resolution open => fixed
2017-11-03 11:43 pschuele Fixed in Version => 2017.08.9 Community Edition