[CalendarServer-changes] [15174] PyCalendar/branches/CalendarServer-5.2/src/pycalendar

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 8 20:16:34 PDT 2015


Revision: 15174
          http://trac.calendarserver.org//changeset/15174
Author:   cdaboo at apple.com
Date:     2015-10-08 20:16:33 -0700 (Thu, 08 Oct 2015)
Log Message:
-----------
Fix RRULE expansion caching issue when the cached period is extended.

Modified Paths:
--------------
    PyCalendar/branches/CalendarServer-5.2/src/pycalendar/recurrence.py
    PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_recurrence.py

Modified: PyCalendar/branches/CalendarServer-5.2/src/pycalendar/recurrence.py
===================================================================
--- PyCalendar/branches/CalendarServer-5.2/src/pycalendar/recurrence.py	2015-10-08 14:52:41 UTC (rev 15173)
+++ PyCalendar/branches/CalendarServer-5.2/src/pycalendar/recurrence.py	2015-10-09 03:16:33 UTC (rev 15174)
@@ -815,24 +815,21 @@
         if self.mCached and (start != self.mCacheStart):
             self.mCached = False
             self.mFullyCached = False
-            self.mRecurrences = []
 
         # Is the current cache complete or does it extend past the requested
         # range end
         if not self.mCached or not self.mFullyCached \
                 and (self.mCacheUpto is None or self.mCacheUpto < range.getEnd()):
-            cache_range = range.duplicate()
 
-            # If partially cached just cache from previous cache end up to new
-            # end
-            if self.mCached:
-                cache_range = PyCalendarPeriod(self.mCacheUpto, range.getEnd())
+            # Always wipe the existing cached items as we always start from the very first instance
+            # so we can properly track the count limit
+            self.mRecurrences = []
 
             # Simple expansion is one where there is no BYXXX rule part
             if not self.hasBy():
-                self.mFullyCached = self.simpleExpand(start, cache_range, self.mRecurrences, float_offset)
+                self.mFullyCached = self.simpleExpand(start, range, self.mRecurrences, float_offset)
             else:
-                self.mFullyCached = self.complexExpand(start, cache_range, self.mRecurrences, float_offset)
+                self.mFullyCached = self.complexExpand(start, range, self.mRecurrences, float_offset)
 
             # Set cache values
             self.mCached = True

Modified: PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_recurrence.py
===================================================================
--- PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_recurrence.py	2015-10-08 14:52:41 UTC (rev 15173)
+++ PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_recurrence.py	2015-10-09 03:16:33 UTC (rev 15174)
@@ -116,6 +116,48 @@
             self.assertNotEqual(hashes[i - 1], hashes[i])
 
 
+    def testWeeklyTwice(self):
+
+        recur = PyCalendarRecurrence()
+        recur.parse("FREQ=WEEKLY")
+        start = PyCalendarDateTime(2014, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(utc=True))
+        end = PyCalendarDateTime(2014, 2, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True))
+        items = []
+        range = PyCalendarPeriod(start, end)
+        recur.expand(PyCalendarDateTime(2014, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")), range, items)
+        self.assertEqual(
+            items,
+            [
+                PyCalendarDateTime(2014, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 8, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 15, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 22, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 29, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+
+            ],
+        )
+
+        start = PyCalendarDateTime(2014, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(utc=True))
+        end = PyCalendarDateTime(2014, 3, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True))
+        items = []
+        range = PyCalendarPeriod(start, end)
+        recur.expand(PyCalendarDateTime(2014, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")), range, items)
+        self.assertEqual(
+            items,
+            [
+                PyCalendarDateTime(2014, 1, 1, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 8, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 15, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 22, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 1, 29, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 2, 5, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 2, 12, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 2, 19, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+                PyCalendarDateTime(2014, 2, 26, 12, 0, 0, tzid=PyCalendarTimezone(tzid="America/New_York")),
+            ],
+        )
+
+
     def testByWeekNoExpand(self):
 
         recur = PyCalendarRecurrence()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151008/66d5d60a/attachment.html>


More information about the calendarserver-changes mailing list