<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14523] CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14523">14523</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-03-06 14:00:19 -0800 (Fri, 06 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>willSplit now also returns an 'is fully in future' flag</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagentrashcan5txdavcaldavdatastoreschedulingicalsplitterpy">CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py</a></li>
<li><a href="#CalendarServerbranchesuserssagentrashcan5txdavcaldavdatastoreschedulingtesttest_icalsplitterpy">CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py</a></li>
<li><a href="#CalendarServerbranchesuserssagentrashcan5txdavcaldavdatastoresqlpy">CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagentrashcan5txdavcaldavdatastoreschedulingicalsplitterpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py (14522 => 14523)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py        2015-03-06 21:42:49 UTC (rev 14522)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/icalsplitter.py        2015-03-06 22:00:19 UTC (rev 14523)
</span><span class="lines">@@ -54,13 +54,19 @@
</span><span class="cx">         @param ical: the iCalendar object to examine
</span><span class="cx">         @type ical: L{Component}
</span><span class="cx"> 
</span><del>-        @return: C{True} if a split is require, C{False} otherwise
-        @rtype: C{bool}
</del><ins>+        @return: A tuple of two booleans:
+            C{True} if a split is required
+            C{True} if event is fully in future
+            The second boolean's value is undefined if the first is True or
+            the event is not recurring, or threshold != -1
+        @rtype: C{tuple} of two C{bool}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+        fullyInFuture = False
+
</ins><span class="cx">         # Must be recurring
</span><span class="cx">         if not ical.isRecurring():
</span><del>-            return False
</del><ins>+            return (False, False)
</ins><span class="cx"> 
</span><span class="cx">         # Look for past/future (cacheExpandedTimeRanges will go one year in the future by default)
</span><span class="cx">         now = self.now.duplicate()
</span><span class="lines">@@ -68,7 +74,13 @@
</span><span class="cx">         instances = ical.cacheExpandedTimeRanges(now)
</span><span class="cx">         instances = sorted(instances.instances.values(), key=lambda x: x.start)
</span><span class="cx">         if len(instances) &lt;= 1 or instances[0].start &gt;= self.past or instances[-1].start &lt; self.now:
</span><del>-            return False
</del><ins>+            # Event is either fully in past or in future
+            if len(instances) == 0 or instances[0].start &gt;= now:
+                # fully in future
+                fullyInFuture = True
+            else:
+                fullyInFuture = False
+            return (False, fullyInFuture)
</ins><span class="cx"> 
</span><span class="cx">         if self.threshold != -1:
</span><span class="cx">             # Make sure there are some overridden components in the past - as splitting only makes sense when
</span><span class="lines">@@ -82,13 +94,13 @@
</span><span class="cx"> 
</span><span class="cx">             # Only split when there is more than one past override to split off
</span><span class="cx">             if past_count &lt; 2:
</span><del>-                return False
</del><ins>+                return (False, False)
</ins><span class="cx"> 
</span><span class="cx">             # Now see if overall size exceeds our threshold
</span><del>-            return len(str(ical)) &gt; self.threshold
</del><ins>+            return (len(str(ical)) &gt; self.threshold, False)
</ins><span class="cx"> 
</span><span class="cx">         else:
</span><del>-            return True
</del><ins>+            return (True, False)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def whereSplit(self, ical, break_point=None, allow_past_the_end=True):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagentrashcan5txdavcaldavdatastoreschedulingtesttest_icalsplitterpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py (14522 => 14523)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py        2015-03-06 21:42:49 UTC (rev 14522)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py        2015-03-06 22:00:19 UTC (rev 14523)
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#1.2 Large, old, non-recurring component&quot;,
</span><span class="lines">@@ -135,7 +135,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.1 Small, old, simple recurring component&quot;,
</span><span class="lines">@@ -153,7 +153,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.2 Large, old, simple recurring component&quot;,
</span><span class="lines">@@ -194,7 +194,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.3 Small, more than a year in the future, simple recurring component&quot;,
</span><span class="lines">@@ -212,7 +212,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, True),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#2.4 Small, all cancelled, simple recurring component&quot;,
</span><span class="lines">@@ -232,7 +232,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, True),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.1 Small, old, recurring with future override&quot;,
</span><span class="lines">@@ -259,7 +259,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#3.2 Large, old, recurring component with future override&quot;,
</span><span class="lines">@@ -309,7 +309,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#4.1 Small, old, recurring with past override&quot;,
</span><span class="lines">@@ -336,7 +336,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#4.2 Large, old, recurring component with one past override&quot;,
</span><span class="lines">@@ -386,7 +386,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#4.2 Large, old, recurring component with two past overrides&quot;,
</span><span class="lines">@@ -445,7 +445,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                True,
</del><ins>+                (True, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#5.1 Small, old, limited recurring with past override&quot;,
</span><span class="lines">@@ -472,7 +472,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#5.2 Large, old, limited recurring component with past override&quot;,
</span><span class="lines">@@ -522,7 +522,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#6.1 Small, old, limited future recurring with past override&quot;,
</span><span class="lines">@@ -549,7 +549,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                False,
</del><ins>+                (False, False),
</ins><span class="cx">             ),
</span><span class="cx">             (
</span><span class="cx">                 &quot;#6.2 Large, old, limited future recurring component with two past overrides&quot;,
</span><span class="lines">@@ -608,7 +608,7 @@
</span><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;,
</span><del>-                True,
</del><ins>+                (True, False),
</ins><span class="cx">             ),
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -616,8 +616,8 @@
</span><span class="cx">             ical = Component.fromString(calendar % self.subs)
</span><span class="cx"> 
</span><span class="cx">             splitter = iCalSplitter(1024, 14)
</span><del>-            will_split = splitter.willSplit(ical)
-            self.assertEqual(will_split, result, msg=&quot;Failed: %s&quot; % (description,))
</del><ins>+            willSplitResult = splitter.willSplit(ical)
+            self.assertEqual(willSplitResult, result, msg=&quot;Failed: %s&quot; % (description,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_split(self):
</span><span class="lines">@@ -2211,7 +2211,7 @@
</span><span class="cx">             ical = Component.fromString(calendar % self.subs)
</span><span class="cx">             splitter = iCalSplitter(1024, 14)
</span><span class="cx">             if title[0] == &quot;1&quot;:
</span><del>-                self.assertTrue(splitter.willSplit(ical), &quot;Failed will split: %s&quot; % (title,))
</del><ins>+                self.assertTrue(splitter.willSplit(ical)[0], &quot;Failed will split: %s&quot; % (title,))
</ins><span class="cx">             icalOld, icalNew = splitter.split(ical)
</span><span class="cx">             relsubs = dict(self.subs)
</span><span class="cx">             relsubs[&quot;uid&quot;] = icalOld.resourceUID()
</span><span class="lines">@@ -2220,8 +2220,8 @@
</span><span class="cx">             self.assertEqual(str(icalOld).replace(&quot;\r\n &quot;, &quot;&quot;), split_past.replace(&quot;\n&quot;, &quot;\r\n&quot;) % relsubs, &quot;Failed past: %s&quot; % (title,))
</span><span class="cx"> 
</span><span class="cx">             # Make sure new items won't split again
</span><del>-            self.assertFalse(splitter.willSplit(icalNew), &quot;Failed future will split: %s&quot; % (title,))
-            self.assertFalse(splitter.willSplit(icalOld), &quot;Failed past will split: %s&quot; % (title,))
</del><ins>+            self.assertFalse(splitter.willSplit(icalNew)[0], &quot;Failed future will split: %s&quot; % (title,))
+            self.assertFalse(splitter.willSplit(icalOld)[0], &quot;Failed past will split: %s&quot; % (title,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_split_negative_count(self):
</span><span class="lines">@@ -2318,7 +2318,7 @@
</span><span class="cx">             ical = Component.fromString(calendar % self.subs)
</span><span class="cx">             splitter = iCalSplitter(100, 0)
</span><span class="cx">             if title[0] == &quot;1&quot;:
</span><del>-                self.assertTrue(splitter.willSplit(ical), &quot;Failed will split: %s&quot; % (title,))
</del><ins>+                self.assertTrue(splitter.willSplit(ical)[0], &quot;Failed will split: %s&quot; % (title,))
</ins><span class="cx">             icalOld, icalNew = splitter.split(ical)
</span><span class="cx">             relsubs = dict(self.subs)
</span><span class="cx">             relsubs[&quot;uid&quot;] = icalOld.resourceUID()
</span><span class="lines">@@ -2497,8 +2497,8 @@
</span><span class="cx">             self.assertEqual(str(icalOld).replace(&quot;\r\n &quot;, &quot;&quot;), split_past.replace(&quot;\n&quot;, &quot;\r\n&quot;) % relsubs, &quot;Failed past: %s&quot; % (title,))
</span><span class="cx"> 
</span><span class="cx">             # Make sure new items won't split again
</span><del>-            self.assertFalse(splitter.willSplit(icalNew), &quot;Failed future will split: %s&quot; % (title,))
-            self.assertFalse(splitter.willSplit(icalOld), &quot;Failed past will split: %s&quot; % (title,))
</del><ins>+            self.assertFalse(splitter.willSplit(icalNew)[0], &quot;Failed future will split: %s&quot; % (title,))
+            self.assertFalse(splitter.willSplit(icalOld)[0], &quot;Failed past will split: %s&quot; % (title,))
</ins><span class="cx"> 
</span><span class="cx">             ical = Component.fromString(calendar % self.subs)
</span><span class="cx">             splitter = iCalSplitter(1024, 14)
</span><span class="lines">@@ -2510,5 +2510,5 @@
</span><span class="cx">             self.assertEqual(str(icalOld).replace(&quot;\r\n &quot;, &quot;&quot;), split_past.replace(&quot;\n&quot;, &quot;\r\n&quot;) % relsubs, &quot;Failed past: %s&quot; % (title,))
</span><span class="cx"> 
</span><span class="cx">             # Make sure new items won't split again
</span><del>-            self.assertFalse(splitter.willSplit(icalNew), &quot;Failed future will split: %s&quot; % (title,))
-            self.assertFalse(splitter.willSplit(icalOld), &quot;Failed past will split: %s&quot; % (title,))
</del><ins>+            self.assertFalse(splitter.willSplit(icalNew)[0], &quot;Failed future will split: %s&quot; % (title,))
+            self.assertFalse(splitter.willSplit(icalOld)[0], &quot;Failed past will split: %s&quot; % (title,))
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagentrashcan5txdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py (14522 => 14523)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py        2015-03-06 21:42:49 UTC (rev 14522)
+++ CalendarServer/branches/users/sagen/trashcan-5/txdav/caldav/datastore/sql.py        2015-03-06 22:00:19 UTC (rev 14523)
</span><span class="lines">@@ -4690,7 +4690,7 @@
</span><span class="cx"> 
</span><span class="cx">         splitter = iCalSplitter(config.Scheduling.Options.Splitting.Size, config.Scheduling.Options.Splitting.PastDays)
</span><span class="cx">         ical = (yield self.component())
</span><del>-        will_split = splitter.willSplit(ical)
</del><ins>+        will_split, fullyInFuture = splitter.willSplit(ical)
</ins><span class="cx">         returnValue(will_split)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -4925,7 +4925,7 @@
</span><span class="cx">             if organizerAddress.record.uid == uid:
</span><span class="cx">                 # If the ORGANIZER is moving the event from trash
</span><span class="cx">                 splitter = iCalSplitter()
</span><del>-                willSplit = splitter.willSplit(caldata)
</del><ins>+                willSplit, fullyInFuture = splitter.willSplit(caldata)
</ins><span class="cx">                 if willSplit:
</span><span class="cx">                     log.debug(&quot;Splitting scheduled event being recovered by organizer from trash&quot;)
</span><span class="cx">                     yield self.split(
</span><span class="lines">@@ -4941,12 +4941,7 @@
</span><span class="cx">                         self,
</span><span class="cx">                     )
</span><span class="cx">                 else:
</span><del>-                    now = DateTime.getNowUTC()
-                    now.setHHMMSS(0, 0, 0)
-                    instances = caldata.cacheExpandedTimeRanges(now)
-                    instances = sorted(instances.instances.values(), key=lambda x: x.start)
-                    if instances[0].start &gt;= now:
-                        # future
</del><ins>+                    if fullyInFuture:
</ins><span class="cx">                         log.debug(&quot;Scheduled event being recovered by organizer from trash, fully in the future&quot;)
</span><span class="cx">                         newdata = caldata.duplicate()
</span><span class="cx">                         newdata.bumpiTIPInfo(doSequence=True)
</span></span></pre>
</div>
</div>

</body>
</html>