[CalendarServer-changes] [9239] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed May 9 16:52:06 PDT 2012


Revision: 9239
          http://trac.macosforge.org/projects/calendarserver/changeset/9239
Author:   glyph at apple.com
Date:     2012-05-09 16:52:06 -0700 (Wed, 09 May 2012)
Log Message:
-----------
Memoize in homeWithUID rather than the specific-ized versions, so that other things can safely call homeWithUID without causing cache-incorrectness effects.

Modified Paths:
--------------
    CalendarServer/trunk/twext/internet/decorate.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/twext/internet/decorate.py
===================================================================
--- CalendarServer/trunk/twext/internet/decorate.py	2012-05-09 21:27:15 UTC (rev 9238)
+++ CalendarServer/trunk/twext/internet/decorate.py	2012-05-09 23:52:06 UTC (rev 9239)
@@ -37,13 +37,13 @@
 
     @param memoAttribute: The name of the attribute on the instance which
         should be used for memoizing the result of this method; the attribute
-        itself must be a dictionary.
-    @type memoAttribute: C{str}
+        itself must be a dictionary.  Alternately, if the specified argument is
+        callable, it is a callable that takes the arguments passed to the
+        decorated method and returns the memo dictionaries.
+    @type memoAttribute: C{str} or C{callable}
 
     @param deferredResult: Whether the result must be a deferred.
-    @type keyArgument: C{bool}
     """
-
     def getarg(argname, argspec, args, kw):
         """
         Get an argument from some arguments.
@@ -88,7 +88,10 @@
 
         def outer(*a, **kw):
             self = a[0]
-            memo = getattr(self, memoAttribute)
+            if callable(memoAttribute):
+                memo = memoAttribute(*a, **kw)
+            else:
+                memo = getattr(self, memoAttribute)
             key = getarg(keyArgument, spec, a, kw)
             if key in memo:
                 memoed = memo[key]
@@ -106,7 +109,6 @@
                 result.addCallback(memoResult)
             elif result is not None:
                 memo[key] = result
-
             return result
 
         return outer

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2012-05-09 21:27:15 UTC (rev 9238)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2012-05-09 23:52:06 UTC (rev 9239)
@@ -380,18 +380,27 @@
         if result and len(result) == 1:
             returnValue(result[0][0])
         raise RuntimeError("Database key %s cannot be determined." % (key,))
-        
 
-    @memoizedKey('uid', '_calendarHomes')
+
     def calendarHomeWithUID(self, uid, create=False):
         return self.homeWithUID(ECALENDARTYPE, uid, create=create)
 
 
-    @memoizedKey("uid", "_addressbookHomes")
     def addressbookHomeWithUID(self, uid, create=False):
         return self.homeWithUID(EADDRESSBOOKTYPE, uid, create=create)
 
 
+    def _determineMemo(self, storeType, uid, create=False):
+        """
+        Determine the memo dictionary to use for homeWithUID.
+        """
+        if storeType == ECALENDARTYPE:
+            return self._calendarHomes
+        else:
+            return self._addressbookHomes
+
+
+    @memoizedKey("uid", _determineMemo)
     def homeWithUID(self, storeType, uid, create=False):
         if storeType not in (ECALENDARTYPE, EADDRESSBOOKTYPE):
             raise RuntimeError("Unknown home type.")
@@ -1083,7 +1092,7 @@
         Retrieve the names of the children in this home.
 
         @return: an iterable of C{str}s.
-        """
+        """ 
         if self._childrenLoaded:
             return succeed(self._sharedChildren.keys())
         else:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120509/3a7ef5e1/attachment.html>


More information about the calendarserver-changes mailing list