changeset 5765:c4ec645b42ce

helpers: cache user_or_none results in beaker long_term cache Avoids repeated expensive 'LIKE' lookup on email addresses extracted from changeset authors. This information is only used for display of changelog information. The cache will never expire - only when the server process expires. That is ok for this very static information and the way it is used.
author Mads Kiilerich <madski@unity3d.com>
date Mon, 14 Mar 2016 16:17:46 +0100
parents b03233c4a438
children 041e8a5a2246
files kallithea/lib/helpers.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/helpers.py	Mon Mar 14 16:17:46 2016 +0100
+++ b/kallithea/lib/helpers.py	Mon Mar 14 16:17:46 2016 +0100
@@ -25,6 +25,7 @@
 import urlparse
 import textwrap
 
+from beaker.cache import cache_region
 from pygments.formatters.html import HtmlFormatter
 from pygments import highlight as code_highlight
 from pylons import url
@@ -477,15 +478,19 @@
     return _type == 'hg'
 
 
+@cache_region('long_term', 'user_or_none')
 def user_or_none(author):
+    """Try to match email part of VCS committer string with a local user - or return None"""
     email = author_email(author)
     if email:
-        user = User.get_by_email(email, cache=True)
+        user = User.get_by_email(email, cache=True) # cache will only use sql_cache_short
         if user is not None:
             return user
     return None
 
 def email_or_none(author):
+    """Try to match email part of VCS committer string with a local user.
+    Return primary email of user, email part of the specified author name, or None."""
     if not author:
         return None
     user = user_or_none(author)