[CalendarServer-changes] [10866] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 7 13:36:39 PST 2013


Revision: 10866
          http://trac.calendarserver.org//changeset/10866
Author:   cdaboo at apple.com
Date:     2013-03-07 13:36:39 -0800 (Thu, 07 Mar 2013)
Log Message:
-----------
Improve memoization of CommonHomeChild so that both name and resourceID mappings are created when one lookup
is done. Remove some unneeded dead properties.

Modified Paths:
--------------
    CalendarServer/trunk/twext/internet/decorate.py
    CalendarServer/trunk/twistedcaldav/caldavxml.py
    CalendarServer/trunk/twistedcaldav/scheduling/caldav/delivery.py
    CalendarServer/trunk/txdav/caldav/datastore/file.py
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/twext/internet/decorate.py
===================================================================
--- CalendarServer/trunk/twext/internet/decorate.py	2013-03-07 18:25:19 UTC (rev 10865)
+++ CalendarServer/trunk/twext/internet/decorate.py	2013-03-07 21:36:39 UTC (rev 10866)
@@ -27,10 +27,29 @@
 
 from twisted.internet.defer import Deferred, succeed
 
+class Memoizable(object):
+    """
+    A class that stores itself in the memo dictionary.
+    """
 
+    def memoMe(self, key, memo):
+        """
+        Add this object to the memo dictionary in whatever fashion is appropriate.
+
+        @param key: key used for lookup
+        @type key: C{object} (typically C{str} or C{int})
+        @param memo: the dict to store to
+        @type memo: C{dict}
+        """
+        raise NotImplementedError
+
+
+
 def memoizedKey(keyArgument, memoAttribute, deferredResult=True):
     """
-    Decorator which memoizes the result of a method on that method's instance.
+    Decorator which memoizes the result of a method on that method's instance. If the instance is derived from
+    class Memoizable, then the memoMe method is used to store the result, otherwise it is stored directly in
+    the dict.
 
     @param keyArgument: The name of the "key" argument.
     @type keyArgument: C{str}
@@ -75,6 +94,7 @@
                 (argname, args, kw, argpos)
             )
 
+
     def decorate(thunk):
         # cheater move to try to get the right argspec from inlineCallbacks.
         # This could probably be more robust, but the 'cell_contents' thing
@@ -103,7 +123,9 @@
 
             if isinstance(result, Deferred):
                 def memoResult(finalResult):
-                    if finalResult is not None:
+                    if isinstance(finalResult, Memoizable):
+                        finalResult.memoMe(key, memo)
+                    elif finalResult is not None:
                         memo[key] = finalResult
                     return finalResult
                 result.addCallback(memoResult)

Modified: CalendarServer/trunk/twistedcaldav/caldavxml.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/caldavxml.py	2013-03-07 18:25:19 UTC (rev 10865)
+++ CalendarServer/trunk/twistedcaldav/caldavxml.py	2013-03-07 21:36:39 UTC (rev 10866)
@@ -1110,21 +1110,6 @@
 
 
 @registerElement
-class Originator (CalDAVElement):
-    """
-    A property on resources in schedule Inbox and Outbox indicating the Originator used
-    for the SCHEDULE operation.
-    (CalDAV-schedule, section x.x.x)
-    """
-    name = "originator"
-    hidden = True
-    protected = True
-
-    allowed_children = {(dav_namespace, "href"): (0, 1)} # NB Minimum is zero because this is a property name
-
-
-
- at registerElement
 class Recipient (CalDAVElement):
     """
     A property on resources in schedule Inbox indicating the Recipients targeted

Modified: CalendarServer/trunk/twistedcaldav/scheduling/caldav/delivery.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/scheduling/caldav/delivery.py	2013-03-07 18:25:19 UTC (rev 10865)
+++ CalendarServer/trunk/twistedcaldav/scheduling/caldav/delivery.py	2013-03-07 21:36:39 UTC (rev 10866)
@@ -197,12 +197,6 @@
                 responses.add(recipient.cuaddr, Failure(exc_value=err), reqstatus=iTIPRequestStatus.NO_AUTHORITY)
                 returnValue(False)
             else:
-                # Store CALDAV:originator property
-                child.writeDeadProperty(caldavxml.Originator(davxml.HRef(self.scheduler.originator.cuaddr)))
-
-                # Store CALDAV:recipient property
-                child.writeDeadProperty(caldavxml.Recipient(davxml.HRef(recipient.cuaddr)))
-
                 # Store CS:schedule-changes property if present
                 if changes:
                     child.writeDeadProperty(changes)

Modified: CalendarServer/trunk/txdav/caldav/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/file.py	2013-03-07 18:25:19 UTC (rev 10865)
+++ CalendarServer/trunk/txdav/caldav/datastore/file.py	2013-03-07 21:36:39 UTC (rev 10866)
@@ -742,8 +742,6 @@
                 PropertyName.fromElement(caldavxml.ScheduleTag),
                 PropertyName.fromElement(customxml.TwistedScheduleMatchETags),
                 PropertyName.fromElement(customxml.TwistedCalendarHasPrivateCommentsProperty),
-                PropertyName.fromElement(caldavxml.Originator),
-                PropertyName.fromElement(caldavxml.Recipient),
                 PropertyName.fromElement(customxml.ScheduleChanges),
             ),
         )

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2013-03-07 18:25:19 UTC (rev 10865)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2013-03-07 21:36:39 UTC (rev 10866)
@@ -1239,11 +1239,11 @@
             ).on(txn)
 
         if instanceIndexingRequired and doInstanceIndexing:
-            yield self._addInstances(component, instances, truncateLowerLimit, txn)
+            yield self._addInstances(component, instances, truncateLowerLimit, isInboxItem, txn)
 
 
     @inlineCallbacks
-    def _addInstances(self, component, instances, truncateLowerLimit, txn):
+    def _addInstances(self, component, instances, truncateLowerLimit, isInboxItem, txn):
         """
         Add the set of supplied instances to the store.
 
@@ -1253,6 +1253,8 @@
         @type instances: L{InstanceList}
         @param truncateLowerLimit: the lower limit for instances
         @type truncateLowerLimit: L{PyCalendarDateTime}
+        @param isInboxItem: indicates if an inbox item
+        @type isInboxItem: C{bool}
         @param txn: transaction to use
         @type txn: L{Transaction}
         """
@@ -1274,14 +1276,14 @@
                 lowerLimitApplied = True
                 continue
 
-            yield self._addInstanceDetails(component, instance.rid, start, end, floating, transp, fbtype, txn)
+            yield self._addInstanceDetails(component, instance.rid, start, end, floating, transp, fbtype, isInboxItem, txn)
 
         # For truncated items we insert a tomb stone lower bound so that a time-range
         # query with just an end bound will match
         if lowerLimitApplied or instances.lowerLimit and len(instances.instances) == 0:
             start = PyCalendarDateTime(1901, 1, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True))
             end = PyCalendarDateTime(1901, 1, 1, 1, 0, 0, tzid=PyCalendarTimezone(utc=True))
-            yield self._addInstanceDetails(component, None, start, end, False, True, "UNKNOWN", txn)
+            yield self._addInstanceDetails(component, None, start, end, False, True, "UNKNOWN", isInboxItem, txn)
 
         # Special - for unbounded recurrence we insert a value for "infinity"
         # that will allow an open-ended time-range to always match it.
@@ -1290,11 +1292,11 @@
         if component.isRecurringUnbounded() or instances.limit and len(instances.instances) == 0:
             start = PyCalendarDateTime(2100, 1, 1, 0, 0, 0, tzid=PyCalendarTimezone(utc=True))
             end = PyCalendarDateTime(2100, 1, 1, 1, 0, 0, tzid=PyCalendarTimezone(utc=True))
-            yield self._addInstanceDetails(component, None, start, end, False, True, "UNKNOWN", txn)
+            yield self._addInstanceDetails(component, None, start, end, False, True, "UNKNOWN", isInboxItem, txn)
 
 
     @inlineCallbacks
-    def _addInstanceDetails(self, component, rid, start, end, floating, transp, fbtype, txn):
+    def _addInstanceDetails(self, component, rid, start, end, floating, transp, fbtype, isInboxItem, txn):
 
         tr = schema.TIME_RANGE
         tpy = schema.TRANSPARENCY
@@ -1308,16 +1310,19 @@
             tr.FBTYPE                      : icalfbtype_to_indexfbtype.get(fbtype, icalfbtype_to_indexfbtype["FREE"]),
             tr.TRANSPARENT                 : transp,
         }, Return=tr.INSTANCE_ID).on(txn))[0][0]
-        peruserdata = component.perUserTransparency(rid)
-        for useruid, usertransp in peruserdata:
-            if usertransp != transp:
-                (yield Insert({
-                    tpy.TIME_RANGE_INSTANCE_ID : instanceid,
-                    tpy.USER_ID                : useruid,
-                    tpy.TRANSPARENT            : usertransp,
-                }).on(txn))
 
+        # Don't do transparency for inbox items - we never do freebusy on inbox
+        if not isInboxItem:
+            peruserdata = component.perUserTransparency(rid)
+            for useruid, usertransp in peruserdata:
+                if usertransp != transp:
+                    (yield Insert({
+                        tpy.TIME_RANGE_INSTANCE_ID : instanceid,
+                        tpy.USER_ID                : useruid,
+                        tpy.TRANSPARENT            : usertransp,
+                    }).on(txn))
 
+
     @inlineCallbacks
     def component(self):
         """
@@ -1966,8 +1971,6 @@
             (
             ),
             (
-                PropertyName.fromElement(caldavxml.Originator),
-                PropertyName.fromElement(caldavxml.Recipient),
                 PropertyName.fromElement(customxml.ScheduleChanges),
             ),
         )

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2013-03-07 18:25:19 UTC (rev 10865)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2013-03-07 21:36:39 UTC (rev 10866)
@@ -50,7 +50,7 @@
 
 from txdav.base.datastore.util import QueryCacher
 
-from twext.internet.decorate import memoizedKey
+from twext.internet.decorate import memoizedKey, Memoizable
 
 from txdav.caldav.icalendarstore import ICalendarTransaction, ICalendarStore
 
@@ -741,6 +741,7 @@
                        imip.ICALUID: Parameter("icaluid"),
                       })
 
+
     @inlineCallbacks
     def imipCreateToken(self, organizer, attendee, icaluid, token=None):
         if not (organizer and attendee and icaluid):
@@ -760,17 +761,20 @@
 
     # Lookup IMIP organizer+attendee+icaluid for token
 
+
     @classproperty
     def _selectIMIPTokenByTokenQuery(cls): #@NoSelf
         imip = schema.IMIP_TOKENS
         return Select([imip.ORGANIZER, imip.ATTENDEE, imip.ICALUID], From=imip,
                       Where=(imip.TOKEN == Parameter("token")))
 
+
     def imipLookupByToken(self, token):
         return self._selectIMIPTokenByTokenQuery.on(self, token=token)
 
     # Lookup IMIP token for organizer+attendee+icaluid
 
+
     @classproperty
     def _selectIMIPTokenQuery(cls): #@NoSelf
         imip = schema.IMIP_TOKENS
@@ -778,10 +782,12 @@
                       Where=(imip.ORGANIZER == Parameter("organizer")).And(
                              imip.ATTENDEE == Parameter("attendee")).And(
                              imip.ICALUID == Parameter("icaluid")))
+
+
     @classproperty
     def _updateIMIPTokenQuery(cls): #@NoSelf
         imip = schema.IMIP_TOKENS
-        return Update({imip.ACCESSED: utcNowSQL,},
+        return Update({imip.ACCESSED: utcNowSQL, },
                       Where=(imip.ORGANIZER == Parameter("organizer")).And(
                              imip.ATTENDEE == Parameter("attendee")).And(
                              imip.ICALUID == Parameter("icaluid")))
@@ -800,25 +806,27 @@
             token = None
         returnValue(token)
 
+
     # Remove IMIP token
-
     @classproperty
     def _removeIMIPTokenQuery(cls): #@NoSelf
         imip = schema.IMIP_TOKENS
         return Delete(From=imip,
                       Where=(imip.TOKEN == Parameter("token")))
 
+
     def imipRemoveToken(self, token):
         return self._removeIMIPTokenQuery.on(self, token=token)
 
+
     # Purge old IMIP tokens
-
     @classproperty
     def _purgeOldIMIPTokensQuery(cls): #@NoSelf
         imip = schema.IMIP_TOKENS
         return Delete(From=imip,
                       Where=(imip.ACCESSED < Parameter("olderThan")))
 
+
     def purgeOldIMIPTokens(self, olderThan):
         """
         @type olderThan: datetime
@@ -1616,6 +1624,7 @@
         results = (yield self._childClass.loadAllObjects(self))
         for result in results:
             self._children[result.name()] = result
+            self._children[result._resourceID] = result
         self._childrenLoaded = True
         returnValue(results)
 
@@ -1628,7 +1637,7 @@
         """
 
         if self._childrenLoaded:
-            return succeed(self._children.keys())
+            return succeed([k for k in self._children.keys() if isinstance(k, str)])
         else:
             return self._childClass.listObjects(self)
 
@@ -2430,7 +2439,7 @@
 
 
 
-class CommonHomeChild(LoggingMixIn, FancyEqMixin, _SharedSyncLogic, HomeChildBase):
+class CommonHomeChild(LoggingMixIn, FancyEqMixin, Memoizable, _SharedSyncLogic, HomeChildBase):
     """
     Common ancestor class of AddressBooks and Calendars.
     """
@@ -2483,6 +2492,19 @@
         self._index = None  # Derived classes need to set this
 
 
+    def memoMe(self, key, memo):
+        """
+        Add this object to the memo dictionary in whatever fashion is appropriate.
+
+        @param key: key used for lookup
+        @type key: C{object} (typically C{str} or C{int})
+        @param memo: the dict to store to
+        @type memo: C{dict}
+        """
+        memo[self._name] = self
+        memo[self._resourceID] = self
+
+
     @classproperty
     def _childNamesForHomeID(cls): #@NoSelf
         bind = cls._bindSchema
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130307/d1c44fc3/attachment-0001.html>


More information about the calendarserver-changes mailing list