<!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>[13940] CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling</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/13940">13940</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-09-04 13:14:20 -0700 (Thu, 04 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Additional debug logging for auto-accept processing.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingfreebusypy">CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/freebusy.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingprocessingpy">CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesreleaseCalendarServer53devtxdavcaldavdatastoreschedulingfreebusypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/freebusy.py (13939 => 13940)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/freebusy.py        2014-09-03 18:36:05 UTC (rev 13939)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/freebusy.py        2014-09-04 20:14:20 UTC (rev 13940)
</span><span class="lines">@@ -106,6 +106,7 @@
</span><span class="cx">     event_details=None,
</span><span class="cx">     logItems=None,
</span><span class="cx">     accountingItems=None,
</span><ins>+    allowCache=True,
</ins><span class="cx"> ):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Run a free busy report on the specified calendar collection
</span><span class="lines">@@ -127,6 +128,7 @@
</span><span class="cx">     @param event_details: a C{list} into which to store extended VEVENT details if not C{None}
</span><span class="cx">     @param logItems: a C{dict} to store logging info to
</span><span class="cx">     @param accountingItems: a C{dict} to store accounting info to
</span><ins>+    @param allowCache: if C{True} the FB cache will be used, otherwise it will never be used
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     # First check the privilege on this collection
</span><span class="lines">@@ -178,12 +180,12 @@
</span><span class="cx">             rich_options[&quot;resource&quot;] = True
</span><span class="cx"> 
</span><span class="cx">     # Try cache
</span><del>-    resources = (yield FBCacheEntry.getCacheEntry(calresource, attendee_uid, timerange)) if config.EnableFreeBusyCache else None
</del><ins>+    resources = (yield FBCacheEntry.getCacheEntry(calresource, attendee_uid, timerange)) if config.EnableFreeBusyCache and allowCache else None
</ins><span class="cx"> 
</span><span class="cx">     if resources is None:
</span><span class="cx"> 
</span><span class="cx">         if accountingItems is not None:
</span><del>-            accountingItems[&quot;fb-uncached&quot;] = accountingItems.get(&quot;fb-uncached&quot;, 0) + 1
</del><ins>+            accountingItems[&quot;fb-cached&quot;] = False
</ins><span class="cx"> 
</span><span class="cx">         caching = False
</span><span class="cx">         if config.EnableFreeBusyCache:
</span><span class="lines">@@ -233,7 +235,7 @@
</span><span class="cx"> 
</span><span class="cx">     else:
</span><span class="cx">         if accountingItems is not None:
</span><del>-            accountingItems[&quot;fb-cached&quot;] = accountingItems.get(&quot;fb-cached&quot;, 0) + 1
</del><ins>+            accountingItems[&quot;fb-cached&quot;] = True
</ins><span class="cx"> 
</span><span class="cx">         # Log extended item
</span><span class="cx">         if logItems is not None:
</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 (13939 => 13940)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py        2014-09-03 18:36:05 UTC (rev 13939)
+++ CalendarServer/branches/release/CalendarServer-5.3-dev/txdav/caldav/datastore/scheduling/processing.py        2014-09-04 20:14:20 UTC (rev 13940)
</span><span class="lines">@@ -555,7 +555,7 @@
</span><span class="cx">                         self.recipient.principal,
</span><span class="cx">                         json.dumps(accounting) + &quot;\r\n&quot;,
</span><span class="cx">                         filename=self.uid.encode(&quot;base64&quot;)[:-1] + &quot;.txt&quot;
</span><del>-                )
</del><ins>+                    )
</ins><span class="cx"> 
</span><span class="cx">                 # Only store inbox item when reply is not sent or always for users
</span><span class="cx">                 store_inbox = store_inbox or self.recipient.principal.getCUType() == &quot;INDIVIDUAL&quot;
</span><span class="lines">@@ -676,11 +676,10 @@
</span><span class="cx">             processed_message, delete_original, rids = iTipProcessing.processCancel(self.message, self.recipient_calendar, autoprocessing=autoprocessed)
</span><span class="cx">             if processed_message:
</span><span class="cx">                 if autoprocessed and accountingEnabled(&quot;AutoScheduling&quot;, self.recipient.principal):
</span><del>-                    accounting = {
-                        &quot;action&quot;: &quot;cancel&quot;,
-                        &quot;when&quot;: PyCalendarDateTime.getNowUTC().getText(),
-                        &quot;deleting&quot;: delete_original,
-                    }
</del><ins>+                    accounting = collections.OrderedDict()
+                    accounting[&quot;when&quot;] = PyCalendarDateTime.getNowUTC().getText()
+                    accounting[&quot;deleting&quot;] = delete_original
+                    accounting[&quot;action&quot;] = &quot;cancel&quot;
</ins><span class="cx">                     emitAccounting(
</span><span class="cx">                         &quot;AutoScheduling&quot;,
</span><span class="cx">                         self.recipient.principal,
</span><span class="lines">@@ -807,11 +806,10 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if accountingEnabled(&quot;AutoScheduling&quot;, self.recipient.principal):
</span><del>-            accounting = {
-                &quot;when&quot;: PyCalendarDateTime.getNowUTC().getText(),
-                &quot;automode&quot;: automode,
-                &quot;changed&quot;: False,
-            }
</del><ins>+            accounting = collections.OrderedDict()
+            accounting[&quot;when&quot;] = PyCalendarDateTime.getNowUTC().getText()
+            accounting[&quot;automode&quot;] = automode
+            accounting[&quot;changed&quot;] = False
</ins><span class="cx">         else:
</span><span class="cx">             accounting = None
</span><span class="cx"> 
</span><span class="lines">@@ -869,7 +867,6 @@
</span><span class="cx">         fbset = [fbcalendar for fbcalendar in fbset if fbcalendar.isUsedForFreeBusy()]
</span><span class="cx">         if accounting is not None:
</span><span class="cx">             accounting[&quot;fbset&quot;] = [testcal.name() for testcal in fbset]
</span><del>-            accounting[&quot;tr&quot;] = []
</del><span class="cx"> 
</span><span class="cx">         for testcal in fbset:
</span><span class="cx"> 
</span><span class="lines">@@ -878,6 +875,10 @@
</span><span class="cx">             tz = testcal.getTimezone()
</span><span class="cx">             tzinfo = tz.gettimezone() if tz is not None else PyCalendarTimezone(utc=True)
</span><span class="cx"> 
</span><ins>+            if accounting is not None:
+                accounting[testcal.name()] = {}
+                accounting[testcal.name()][&quot;tr&quot;] = []
+
</ins><span class="cx">             # Now do search for overlapping time-range and set instance.free based
</span><span class="cx">             # on whether there is an overlap or not.
</span><span class="cx">             # NB Do this in reverse order so that the date farthest in the future is tested first - that will
</span><span class="lines">@@ -904,25 +905,42 @@
</span><span class="cx">                             end=str(makeTimedUTC(instance.end)),
</span><span class="cx">                         )
</span><span class="cx"> 
</span><del>-                        yield generateFreeBusyInfo(testcal, fbinfo, tr, 0, uid, servertoserver=True, accountingItems=accounting if len(instances) == 1 else None)
</del><ins>+                        if accounting is None:
+                            yield generateFreeBusyInfo(testcal, fbinfo, tr, 0, uid, servertoserver=True)
+                        else:
+                            # Do this twice if cache is used and compare results
+                            details1 = {}
+                            yield generateFreeBusyInfo(testcal, fbinfo, tr, 0, uid, servertoserver=True, accountingItems=details1)
+                            if &quot;useCache&quot; not in accounting[testcal.name()]:
+                                accounting[testcal.name()][&quot;useCache&quot;] = details1
</ins><span class="cx"> 
</span><ins>+                            if accounting[testcal.name()][&quot;useCache&quot;][&quot;fb-cached&quot;]:
+                                fbinfo_nocache = ([], [], [])
+                                details2 = {}
+                                yield generateFreeBusyInfo(testcal, fbinfo_nocache, tr, 0, uid, servertoserver=True, accountingItems=details2, allowCache=False)
+                                if &quot;noCache&quot; not in accounting[testcal.name()]:
+                                    accounting[testcal.name()][&quot;noCache&quot;] = details2
+                                if fbinfo != fbinfo_nocache:
+                                    log.error(&quot;Auto-accept free busy cache inconsistent with database query&quot;)
+                                    accounting[testcal.name()][&quot;badCache&quot;] = (details1, details2)
+
</ins><span class="cx">                         # If any fbinfo entries exist we have an overlap
</span><span class="cx">                         if len(fbinfo[0]) or len(fbinfo[1]) or len(fbinfo[2]):
</span><span class="cx">                             instance.free = False
</span><span class="cx">                         if accounting is not None:
</span><del>-                            accounting[&quot;tr&quot;].insert(0, (tr.attributes[&quot;start&quot;], tr.attributes[&quot;end&quot;], instance.free,))
</del><ins>+                            accounting[testcal.name()][&quot;tr&quot;].insert(0, (tr.attributes[&quot;start&quot;], tr.attributes[&quot;end&quot;], instance.free,))
</ins><span class="cx">                     except QueryMaxResources:
</span><span class="cx">                         instance.free = False
</span><span class="cx">                         log.info(&quot;Exceeded number of matches whilst trying to find free-time.&quot;)
</span><span class="cx">                         if accounting is not None:
</span><del>-                            accounting[&quot;problem&quot;] = &quot;Exceeded number of matches&quot;
</del><ins>+                            accounting[testcal.name()][&quot;problem&quot;] = &quot;Exceeded number of matches&quot;
</ins><span class="cx"> 
</span><span class="cx">             # If everything is declined we can exit now
</span><span class="cx">             if not any([instance.free for instance in instances]):
</span><span class="cx">                 break
</span><span class="cx"> 
</span><del>-        if accounting is not None:
-            accounting[&quot;tr&quot;] = accounting[&quot;tr&quot;][:30]
</del><ins>+            if accounting is not None:
+                accounting[testcal.name()][&quot;tr&quot;] = accounting[testcal.name()][&quot;tr&quot;][:30]
</ins><span class="cx"> 
</span><span class="cx">         # Now adjust the instance.partstat currently set to &quot;NEEDS-ACTION&quot; to the
</span><span class="cx">         # value determined by auto-accept logic based on instance.free state. However,
</span></span></pre>
</div>
</div>

</body>
</html>