# HG changeset patch # User Mads Kiilerich # Date 2016-03-14 16:17:46 # Node ID c4ec645b42ceb39ba19207c44480462c6a7c12a8 # Parent b03233c4a438d78103eb5b48b48f0dd04a5805b6 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. diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -25,6 +25,7 @@ import re 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 @@ def is_hg(repository): 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)