You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/12/20 19:50:50 UTC

[24/36] git commit: [#7009] cache icon resource resolution instead of icon urls, so http/https doesn't get wrongly cached

[#7009] cache icon resource resolution instead of icon urls, so http/https doesn't get wrongly cached

Resource lookup is the slow part (although not that slow), so just
cache that.  And encapsulate via the @memoize decorator.


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/4ab4c42e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4ab4c42e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4ab4c42e

Branch: refs/heads/db/6388
Commit: 4ab4c42e196e3cd2f617135498f832445bcb7a14
Parents: 27d93da
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Fri Dec 20 01:51:17 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Dec 20 01:51:17 2013 +0000

----------------------------------------------------------------------
 Allura/allura/app.py | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4ab4c42e/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 3e691f3..85673c5 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -37,7 +37,7 @@ from allura.lib import helpers as h
 from allura.lib.security import require, has_access, require_access
 from allura import model
 from allura.controllers import BaseController
-from allura.lib.decorators import require_post, event_handler
+from allura.lib.decorators import require_post, event_handler, memoize
 from allura.lib.utils import permanent_redirect, ConfigProxy
 
 log = logging.getLogger(__name__)
@@ -369,22 +369,15 @@ class Application(object):
         :attr:`icons`.
 
         """
-        cached = getattr(cls, '_icon_url_cache', {}).get(size)
-        if cached is not None:
-            return cached
-
-        if not hasattr(cls, '_icon_url_cache'):
-            setattr(cls, '_icon_url_cache', {})
-
         resource, url = cls.icons.get(size), ''
         if resource:
             resource_path = os.path.join('nf', resource)
             url = (g.forge_static(resource) if cls.has_resource(resource_path)
                     else g.theme_href(resource))
-        cls._icon_url_cache[size] = url
         return url
 
     @classmethod
+    @memoize
     def has_resource(cls, resource_path):
         """Determine whether this Application has the resource pointed to by
         ``resource_path``.