<!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>[13787] CalendarServer/branches/release/CalendarServer-5.3-dev</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/13787">13787</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-07-24 08:57:13 -0700 (Thu, 24 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Don't update the TIME_RANGE table when there are no changes to it.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavstdconfigpy">CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingicaldiffpy">CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/icaldiff.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingprocessingpy">CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoresqlpy">CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoretesttest_sqlpy">CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/test/test_sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesreleaseCalendarServer53devtwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py (13786 => 13787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py        2014-07-24 15:56:17 UTC (rev 13786)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/twistedcaldav/stdconfig.py        2014-07-24 15:57:13 UTC (rev 13787)
</span><span class="lines">@@ -1012,6 +1012,7 @@
</span><span class="cx">     &quot;FreeBusyIndexExpandAheadDays&quot;: 365,
</span><span class="cx">     &quot;FreeBusyIndexExpandMaxDays&quot;: 5 * 365,
</span><span class="cx">     &quot;FreeBusyIndexDelayedExpand&quot;: True,
</span><ins>+    &quot;FreeBusyIndexSmartUpdate&quot;: True,
</ins><span class="cx"> 
</span><span class="cx">     # The RootResource uses a twext property store. Specify the class here
</span><span class="cx">     &quot;RootResourcePropStoreClass&quot;: &quot;twext.web2.dav.xattrprops.xattrPropertyStore&quot;,
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingicaldiffpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/icaldiff.py (13786 => 13787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/icaldiff.py        2014-07-24 15:56:17 UTC (rev 13786)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/icaldiff.py        2014-07-24 15:57:13 UTC (rev 13787)
</span><span class="lines">@@ -692,7 +692,7 @@
</span><span class="cx">         return partstatChanged
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def whatIsDifferent(self):
</del><ins>+    def whatIsDifferent(self, isiTip=True):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Compare the two calendar objects in their entirety and return a list of properties
</span><span class="cx">         and PARTSTAT parameters that are different.
</span><span class="lines">@@ -721,7 +721,7 @@
</span><span class="cx">         for key in (oldset &amp; newset):
</span><span class="cx">             component1 = oldmap[key]
</span><span class="cx">             component2 = newmap[key]
</span><del>-            self._diffComponents(component1, component2, rids)
</del><ins>+            self._diffComponents(component1, component2, rids, isiTip)
</ins><span class="cx"> 
</span><span class="cx">         # Now verify that each additional component in oldset matches a derived component in newset
</span><span class="cx">         for key in oldset - newset:
</span><span class="lines">@@ -729,7 +729,7 @@
</span><span class="cx">             newcomponent = self.newcalendar.deriveInstance(key[2])
</span><span class="cx">             if newcomponent is None:
</span><span class="cx">                 continue
</span><del>-            self._diffComponents(oldcomponent, newcomponent, rids)
</del><ins>+            self._diffComponents(oldcomponent, newcomponent, rids, isiTip)
</ins><span class="cx"> 
</span><span class="cx">         # Now verify that each additional component in oldset matches a derived component in newset
</span><span class="cx">         for key in newset - oldset:
</span><span class="lines">@@ -737,24 +737,59 @@
</span><span class="cx">             if oldcomponent is None:
</span><span class="cx">                 continue
</span><span class="cx">             newcomponent = newmap[key]
</span><del>-            self._diffComponents(oldcomponent, newcomponent, rids)
</del><ins>+            self._diffComponents(oldcomponent, newcomponent, rids, isiTip)
</ins><span class="cx"> 
</span><span class="cx">         return rids
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _componentDuplicateAndNormalize(self, comp):
</del><ins>+    TRPROPS = frozenset((
+        &quot;DTSTART&quot;,
+        &quot;DTEND&quot;,
+        &quot;DURATION&quot;,
+        &quot;DUE&quot;,
+        &quot;RECURRENCE-ID&quot;,
+        &quot;RRULE&quot;,
+        &quot;RDATE&quot;,
+        &quot;EXDATE&quot;,
+        &quot;STATUS&quot;,
+        &quot;TRANSP&quot;,
+        &quot;X-APPLE-TRAVEL-START&quot;,
+        &quot;X-APPLE-TRAVEL-DURATION&quot;,
+        &quot;X-APPLE-TRAVEL-RETURN&quot;,
+        &quot;X-APPLE-TRAVEL-RETURN-DURATION&quot;,
+    ))
+
+    def timeRangeDifference(self):
+        &quot;&quot;&quot;
+        Is there a difference between the two components that implies a change to the time or
+        transparency/status of any instance.
+
+        @return: L{True} if there is such a change, L{False} otherwise
+        @rtype: L{bool}
+        &quot;&quot;&quot;
+
+        for props in self.whatIsDifferent(isiTip=False).values():
+            props = frozenset(props.keys())
+            if props &amp; self.TRPROPS:
+                return True
+        else:
+            return False
+
+
+    def _componentDuplicateAndNormalize(self, comp, isiTip=True):
</ins><span class="cx">         comp = comp.duplicate()
</span><span class="cx">         comp.normalizePropertyValueLists(&quot;EXDATE&quot;)
</span><del>-        comp.removePropertyParameters(&quot;ORGANIZER&quot;, (&quot;SCHEDULE-STATUS&quot;,))
-        comp.removePropertyParameters(&quot;ATTENDEE&quot;, (&quot;SCHEDULE-STATUS&quot;, &quot;SCHEDULE-FORCE-SEND&quot;,))
</del><span class="cx">         comp.removeAlarms()
</span><span class="cx">         comp.normalizeAll()
</span><span class="cx">         comp.normalizeAttachments()
</span><del>-        iTipGenerator.prepareSchedulingMessage(comp, reply=True)
</del><ins>+        if isiTip:
+            comp.removePropertyParameters(&quot;ORGANIZER&quot;, (&quot;SCHEDULE-STATUS&quot;,))
+            comp.removePropertyParameters(&quot;ATTENDEE&quot;, (&quot;SCHEDULE-STATUS&quot;, &quot;SCHEDULE-FORCE-SEND&quot;,))
+            iTipGenerator.prepareSchedulingMessage(comp, reply=True)
</ins><span class="cx">         return comp
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _diffComponents(self, comp1, comp2, rids):
</del><ins>+    def _diffComponents(self, comp1, comp2, rids, isiTip=True):
</ins><span class="cx"> 
</span><span class="cx">         assert isinstance(comp1, Component) and isinstance(comp2, Component)
</span><span class="cx"> 
</span><span class="lines">@@ -763,8 +798,8 @@
</span><span class="cx">             return
</span><span class="cx"> 
</span><span class="cx">         # Duplicate then normalize for comparison
</span><del>-        comp1 = self._componentDuplicateAndNormalize(comp1)
-        comp2 = self._componentDuplicateAndNormalize(comp2)
</del><ins>+        comp1 = self._componentDuplicateAndNormalize(comp1, isiTip)
+        comp2 = self._componentDuplicateAndNormalize(comp2, isiTip)
</ins><span class="cx"> 
</span><span class="cx">         # Diff all the properties
</span><span class="cx">         propdiff = set(comp1.properties()) ^ set(comp2.properties())
</span><span class="lines">@@ -773,7 +808,6 @@
</span><span class="cx">         propsChanged = {}
</span><span class="cx">         for prop in propdiff:
</span><span class="cx">             if prop.name() in (
</span><del>-                &quot;TRANSP&quot;,
</del><span class="cx">                 &quot;DTSTAMP&quot;,
</span><span class="cx">                 &quot;CREATED&quot;,
</span><span class="cx">                 &quot;LAST-MODIFIED&quot;,
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingprocessingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py (13786 => 13787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py        2014-07-24 15:56:17 UTC (rev 13786)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py        2014-07-24 15:57:13 UTC (rev 13787)
</span><span class="lines">@@ -162,7 +162,7 @@
</span><span class="cx">         self.recipient_calendar_resource = None
</span><span class="cx">         calendar_resource = (yield getCalendarObjectForRecord(self.txn, self.recipient.principal, self.uid))
</span><span class="cx">         if calendar_resource:
</span><del>-            self.recipient_calendar = (yield calendar_resource.componentForUser(self.recipient.principal.uid))
</del><ins>+            self.recipient_calendar = (yield calendar_resource.componentForUser(self.recipient.principal.uid)).duplicate()
</ins><span class="cx">             self.recipient_calendar_resource = calendar_resource
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/sql.py (13786 => 13787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/sql.py        2014-07-24 15:56:17 UTC (rev 13786)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/sql.py        2014-07-24 15:57:13 UTC (rev 13787)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx"> from twistedcaldav.memcacher import Memcacher
</span><span class="cx"> 
</span><span class="cx"> from txdav.base.propertystore.base import PropertyName
</span><ins>+from txdav.caldav.datastore.scheduling.icaldiff import iCalDiff
</ins><span class="cx"> from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
</span><span class="cx"> from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
</span><span class="cx"> from txdav.caldav.datastore.util import AttachmentRetrievalTransport, \
</span><span class="lines">@@ -1746,7 +1747,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def preservePrivateComments(self, component, inserting):
</del><ins>+    def preservePrivateComments(self, component, inserting, internal_state):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Check for private comments on the old resource and the new resource and re-insert
</span><span class="cx">         ones that are lost.
</span><span class="lines">@@ -1765,7 +1766,7 @@
</span><span class="cx">                 &quot;X-CALENDARSERVER-ATTENDEE-COMMENT&quot;,
</span><span class="cx">             ))
</span><span class="cx"> 
</span><del>-            if old_has_private_comments and not new_has_private_comments:
</del><ins>+            if old_has_private_comments and not new_has_private_comments and internal_state == ComponentUpdateState.NORMAL:
</ins><span class="cx">                 # Transfer old comments to new calendar
</span><span class="cx">                 log.debug(&quot;Organizer private comment properties were entirely removed by the client. Restoring existing properties.&quot;)
</span><span class="cx">                 old_calendar = (yield self.componentForUser())
</span><span class="lines">@@ -1779,7 +1780,7 @@
</span><span class="cx">             # to raise an error to prevent that so the client bugs can be tracked down.
</span><span class="cx"> 
</span><span class="cx">             # Look for properties with duplicate &quot;X-CALENDARSERVER-ATTENDEE-REF&quot; values in the same component
</span><del>-            if component.hasDuplicatePrivateComments(doFix=config.RemoveDuplicatePrivateComments):
</del><ins>+            if component.hasDuplicatePrivateComments(doFix=config.RemoveDuplicatePrivateComments) and internal_state == ComponentUpdateState.NORMAL:
</ins><span class="cx">                 raise DuplicatePrivateCommentsError(&quot;Duplicate X-CALENDARSERVER-ATTENDEE-COMMENT properties present.&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2196,7 +2197,7 @@
</span><span class="cx">                 self.validAccess(component, inserting, internal_state)
</span><span class="cx"> 
</span><span class="cx">             # Preserve private comments
</span><del>-            yield self.preservePrivateComments(component, inserting)
</del><ins>+            yield self.preservePrivateComments(component, inserting, internal_state)
</ins><span class="cx"> 
</span><span class="cx">             managed_copied, managed_removed = (yield self.resourceCheckAttachments(component, inserting))
</span><span class="cx"> 
</span><span class="lines">@@ -2215,7 +2216,7 @@
</span><span class="cx">             yield self._lockUID(component, inserting, internal_state)
</span><span class="cx"> 
</span><span class="cx">             # Preserve private comments
</span><del>-            yield self.preservePrivateComments(component, inserting)
</del><ins>+            yield self.preservePrivateComments(component, inserting, internal_state)
</ins><span class="cx"> 
</span><span class="cx">             # Fix broken VTODOs
</span><span class="cx">             yield self.replaceMissingToDoProperties(component, inserting, internal_state)
</span><span class="lines">@@ -2259,6 +2260,13 @@
</span><span class="cx">                 if did_implicit_action:
</span><span class="cx">                     self._componentChanged = True
</span><span class="cx"> 
</span><ins>+            if not hasattr(self, &quot;tr_change&quot;):
+                if inserting or hasattr(component, &quot;noInstanceIndexing&quot;) or not config.FreeBusyIndexSmartUpdate:
+                    self.tr_change = None
+                else:
+                    oldcomponent = yield self.componentForUser()
+                    self.tr_change = iCalDiff(oldcomponent, component, False).timeRangeDifference()
+
</ins><span class="cx">             # Always do the per-user data merge right before we store
</span><span class="cx">             component = (yield self.mergePerUserData(component, inserting))
</span><span class="cx"> 
</span><span class="lines">@@ -2331,7 +2339,12 @@
</span><span class="cx">         # In some cases there is no need to remove/rebuild the instance index because we know no time or
</span><span class="cx">         # freebusy related properties have changed (e.g. an attendee reply and refresh). In those cases
</span><span class="cx">         # the component will have a special attribute present to let us know to suppress the instance indexing.
</span><del>-        instanceIndexingRequired = not getattr(component, &quot;noInstanceIndexing&quot;, False) or inserting or reCreate
</del><ins>+        if inserting or reCreate:
+            instanceIndexingRequired = True
+        elif getattr(component, &quot;noInstanceIndexing&quot;, False):
+            instanceIndexingRequired = False
+        else:
+            instanceIndexingRequired = getattr(self, &quot;tr_change&quot;, True) in (None, True)
</ins><span class="cx"> 
</span><span class="cx">         if instanceIndexingRequired:
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/test/test_sql.py (13786 => 13787)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/test/test_sql.py        2014-07-24 15:56:17 UTC (rev 13786)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/test/test_sql.py        2014-07-24 15:57:13 UTC (rev 13787)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx"> from txdav.caldav.datastore.scheduling.scheduler import ScheduleResponseQueue
</span><span class="cx"> from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
</span><span class="cx"> from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
</span><ins>+from txdav.caldav.datastore.sql import CalendarObject
</ins><span class="cx"> from txdav.caldav.datastore.test.common import CommonTests as CalendarCommonTests, \
</span><span class="cx">     test_event_text, OTHER_HOME_UID
</span><span class="cx"> from txdav.caldav.datastore.test.test_file import setUpCalendarStore
</span><span class="lines">@@ -1456,6 +1457,7 @@
</span><span class="cx">         # Re-add event with re-indexing
</span><span class="cx">         calendar = yield self.calendarUnderTest()
</span><span class="cx">         calendarObject = yield self.calendarObjectUnderTest(name=&quot;indexing.ics&quot;)
</span><ins>+        calendarObject.tr_change = True
</ins><span class="cx">         yield calendarObject.setComponent(component)
</span><span class="cx">         instances2 = yield calendarObject.instances()
</span><span class="cx">         self.assertNotEqual(
</span><span class="lines">@@ -6321,3 +6323,572 @@
</span><span class="cx">         cobjs = yield cal.calendarObjects()
</span><span class="cx">         self.assertEqual(len(cobjs), 1)
</span><span class="cx">         yield self.failUnlessFailure(cobjs[0].splitAt(PyCalendarDateTime.parseText(&quot;%(now_fwd25)s&quot; % self.subs)), InvalidSplit)
</span><ins>+
+
+
+class TimeRangeUpdateOptimization(CommonCommonTests, unittest.TestCase):
+    &quot;&quot;&quot;
+    CalendarObject splitting tests
+    &quot;&quot;&quot;
+
+    EVENT1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event #2
+DTSTAMP:20100203T013909Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T130000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT4 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+TRANSP:TRANSPARENT
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT5 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+STATUS:CANCELLED
+DTSTAMP:20100203T013909Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT6 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+X-APPLE-TRAVEL-DURATION;VALUE=DURATION:PT1H
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT7 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+RRULE:FREQ=DAILY
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT8 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+RRULE:FREQ=DAILY;COUNT=10
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT9 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+RRULE:FREQ=DAILY
+EXDATE:{now}T120000Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    EVENT10 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+RRULE:FREQ=DAILY
+RDATE:{now}T150000Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(TimeRangeUpdateOptimization, self).setUp()
+        self._sqlCalendarStore = yield buildCalendarStore(self, self.notifierFactory)
+        yield self.populate()
+
+        self.now = PyCalendarDateTime.getNowUTC()
+        self.now.setDateOnly(True)
+
+        self.trcount = 0
+        base_addInstances = CalendarObject._addInstances
+        def __addInstances(*args):
+            self.trcount += 1
+            return base_addInstances(*args)
+        self.patch(CalendarObject, &quot;_addInstances&quot;, __addInstances)
+
+        self.patch(config, &quot;FreeBusyIndexDelayedExpand&quot;, False)
+        self.patch(config, &quot;FreeBusyIndexSmartUpdate&quot;, True)
+
+
+    @inlineCallbacks
+    def populate(self):
+        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
+        self.notifierFactory.reset()
+
+
+    def storeUnderTest(self):
+        &quot;&quot;&quot;
+        Create and return a L{CalendarStore} for testing.
+        &quot;&quot;&quot;
+        return self._sqlCalendarStore
+
+
+    @property
+    def requirements(self):
+        return {
+            &quot;home1&quot;: {
+                &quot;calendar_1&quot;: {},
+            },
+            &quot;user01&quot;: {
+                &quot;calendar&quot;: {},
+                &quot;inbox&quot;: {},
+            },
+            &quot;user02&quot;: {
+                &quot;calendar&quot;: {},
+                &quot;inbox&quot;: {},
+            },
+        }
+
+
+    @inlineCallbacks
+    def test_initalPUT(self):
+        &quot;&quot;&quot;
+        Test that initial PUT causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withoutTRChange(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT does not cause T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT2.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withoutOptimization(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        self.patch(config, &quot;FreeBusyIndexSmartUpdate&quot;, False)
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT does cause T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT2.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withTRChange(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT3.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withTranspChange(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT4.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withStatusChange(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT5.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withTravelTimeChange(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT6.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withRRULEChange(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT7.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT8.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withEXDATEAdd(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT7.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT9.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    @inlineCallbacks
+    def test_updatePUT_withRDATEAdd(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest()
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.EVENT7.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 1)
+
+        # Second PUT causes T-R change
+        cobj = yield self.calendarObjectUnderTest()
+        yield cobj.setComponent(Component.fromString(self.EVENT10.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 2)
+
+
+    INVITE1 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    INVITE2 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    INVITE3 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T120000Z
+DURATION:PT1H
+SUMMARY:New Event #2
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    INVITE4 = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100203T013849Z
+UID:uid1
+DTSTART:{now}T140000Z
+DURATION:PT1H
+SUMMARY:New Event #2
+DTSTAMP:20100203T013909Z
+ORGANIZER:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01@example.com
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user02@example.com
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;
+
+    @inlineCallbacks
+    def test_schedulingPUT(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.INVITE1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 3)
+
+        # Attendee reply does not cause T-R change (except for inbox item and attendee resource transp change)
+        cal = yield self.calendarUnderTest(home=&quot;user02&quot;, name=&quot;calendar&quot;)
+        cobjs = yield cal.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        yield cobjs[0].setComponent(Component.fromString(self.INVITE2.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 5)
+
+        # Organizer summary change does not cause T-R change (except for inbox item)
+        cobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;)
+        yield cobj.setComponent(Component.fromString(self.INVITE3.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 6)
+
+        # Organizer dtstart change causes T-R change
+        cobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;)
+        yield cobj.setComponent(Component.fromString(self.INVITE4.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 9)
+
+
+    @inlineCallbacks
+    def test_schedulingPUT_withoutOptimization(self):
+        &quot;&quot;&quot;
+        Test that second PUT withe time change causes a TIME_RANGE update
+        &quot;&quot;&quot;
+
+        self.patch(config, &quot;FreeBusyIndexSmartUpdate&quot;, False)
+
+        # First PUT causes T-R change
+        cal = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield cal.createObjectResourceWithName(&quot;1.ics&quot;, Component.fromString(self.INVITE1.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 3)
+
+        # Attendee reply does cause T-R change (except for organizer update)
+        cal = yield self.calendarUnderTest(home=&quot;user02&quot;, name=&quot;calendar&quot;)
+        cobjs = yield cal.calendarObjects()
+        self.assertEqual(len(cobjs), 1)
+        yield cobjs[0].setComponent(Component.fromString(self.INVITE2.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 5)
+
+        # Organizer summary change causes T-R change
+        cobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;)
+        yield cobj.setComponent(Component.fromString(self.INVITE3.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 8)
+
+        # Organizer dtstart change causes T-R change
+        cobj = yield self.calendarObjectUnderTest(home=&quot;user01&quot;, calendar_name=&quot;calendar&quot;)
+        yield cobj.setComponent(Component.fromString(self.INVITE4.format(now=self.now.getText())))
+        yield self.commit()
+
+        self.assertEqual(self.trcount, 11)
</ins></span></pre>
</div>
</div>

</body>
</html>