[CalendarServer-changes] [2275] CalendarServer/branches/users/cdaboo/better-proxy-db-2269/ twistedcaldav/extensions.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 2 10:32:42 PDT 2008


Revision: 2275
          http://trac.macosforge.org/projects/calendarserver/changeset/2275
Author:   cdaboo at apple.com
Date:     2008-04-02 10:32:41 -0700 (Wed, 02 Apr 2008)

Log Message:
-----------
Cache matchPrincipal results on a per-request basis so we don't have to do the same group membership tests
multiple times in the same request.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/better-proxy-db-2269/twistedcaldav/extensions.py

Modified: CalendarServer/branches/users/cdaboo/better-proxy-db-2269/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/users/cdaboo/better-proxy-db-2269/twistedcaldav/extensions.py	2008-04-02 17:02:53 UTC (rev 2274)
+++ CalendarServer/branches/users/cdaboo/better-proxy-db-2269/twistedcaldav/extensions.py	2008-04-02 17:32:41 UTC (rev 2275)
@@ -325,7 +325,30 @@
 
         return acl
     
+    @deferredGenerator
+    def matchPrincipal(self, principal1, principal2, request):
+        """
+        Implementation of DAVResource.matchPrincipal that caches the principal match
+        for the duration of a request. This avoids having to do repeated group membership
+        tests when privileges on multiple resources are determined.
+        """
+        
+        if not hasattr(request, "matchPrincipalCache"):
+            request.matchPrincipalCache = {}
 
+        # The interesting part of a principal is it's one child
+        principals = (principal1, principal2)
+        cache_key = tuple([str(p.children[0]) for p in principals])
+
+        match = request.matchPrincipalCache.get(cache_key, None)
+        if match is None:
+            match = waitForDeferred(super(DAVResource, self).matchPrincipal(principal1, principal2, request))
+            yield match
+            match = match.getResult()
+            request.matchPrincipalCache[cache_key] = match
+            
+        yield match
+
 class DAVPrincipalResource (SuperDAVPrincipalResource):
     """
     Extended L{twisted.web2.dav.static.DAVFile} implementation.
@@ -342,7 +365,7 @@
         return super(DAVPrincipalResource, self).readProperty(property, request)
 
     def resourceType(self):
-        # Allow live property to be overriden by dead property
+        # Allow live property to be overridden by dead property
         if self.deadProperties().contains((dav_namespace, "resourcetype")):
             return self.deadProperties().get((dav_namespace, "resourcetype"))
         if self.isCollection():

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080402/cc7d63b3/attachment.html


More information about the calendarserver-changes mailing list