changeset 1830:ee61e0639afb

speed up ACLs: reuse page and acl objects
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 25 Feb 2007 22:51:01 +0100
parents 6a162bb60560
children bff1080d37d4
files MoinMoin/Page.py MoinMoin/security/__init__.py
diffstat 2 files changed, 33 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Feb 25 20:41:56 2007 +0100
+++ b/MoinMoin/Page.py	Sun Feb 25 22:51:01 2007 +0100
@@ -1505,22 +1505,29 @@
         @rtype: MoinMoin.security.AccessControlList
         @return: ACL of this page
         """
-        request.clock.start('getACL')
-        # Try the cache or parse acl and update the cache
-        currentRevision = self.current_rev()
-        cache_name = self.page_name
-        cache_key = 'acl'
-        cache_data = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
-        if cache_data is None:
-            aclRevision, acl = None, None
-        else:
-            aclRevision, acl = cache_data
-        if aclRevision != currentRevision:
-            acl = self.parseACL()
-            cache_data = (currentRevision, acl)
-            request.cfg.cache.meta.putItem(request, cache_name, cache_key, cache_data)
-        request.clock.stop('getACL')
-        return acl
+        try:
+            return self.__acl # for request.page, this is n-1 times used
+        except AttributeError:
+            # the caching here is still useful for pages != request.page,
+            # when we have multiple page objects for the same page name.
+            request.clock.start('getACL')
+            # Try the cache or parse acl and update the cache
+            currentRevision = self.current_rev()
+            cache_name = self.page_name
+            cache_key = 'acl'
+            cache_data = request.cfg.cache.meta.getItem(request, cache_name, cache_key)
+            if cache_data is None:
+                aclRevision, acl = None, None
+            else:
+                aclRevision, acl = cache_data
+            logging.debug("currrev: %r, cachedaclrev: %r" % (currentRevision, aclRevision))
+            if aclRevision != currentRevision:
+                acl = self.parseACL()
+                cache_data = (currentRevision, acl)
+                request.cfg.cache.meta.putItem(request, cache_name, cache_key, cache_data)
+            self.__acl = acl
+            request.clock.stop('getACL')
+            return acl
 
     def parseACL(self):
         """ Return ACLs parsed from the last available revision 
--- a/MoinMoin/security/__init__.py	Sun Feb 25 20:41:56 2007 +0100
+++ b/MoinMoin/security/__init__.py	Sun Feb 25 22:51:01 2007 +0100
@@ -16,6 +16,7 @@
 
 import re
 from MoinMoin import user
+from MoinMoin.Page import Page
 
 #############################################################################
 ### Basic Permissions Interface -- most features enabled by default
@@ -32,8 +33,6 @@
     def __init__(self, user):
         """ Calculate the permissons `user` has.
         """
-        from MoinMoin.Page import Page
-        self.Page = Page
         self.name = user.name
         self.request = user._request
 
@@ -50,9 +49,16 @@
             checking function for it. Else raise an error.
         """
         request = self.request
-        Page = self.Page
         if attr in request.cfg.acl_rights_valid:
-            return lambda pagename, Page=Page, request=request, attr=attr: Page(request, pagename).getACL(request).may(request, self.name, attr)
+            def check(request, pagename, user, right):
+                if pagename == request.page.page_name:
+                    p = request.page # reuse is good
+                else:
+                    p = Page(request, pagename)
+                acl = p.getACL(request) # this will be fast in a reused page obj
+                return acl.may(request, user, right)
+            return lambda pagename: check(self.request, pagename, self.name, attr)
+            ##return lambda pagename, Page=Page, request=request, attr=attr: Page(request, pagename).getACL(request).may(request, self.name, attr)
         else:
             raise AttributeError, attr