diff options
author | Dan McGee <dan@archlinux.org> | 2013-12-01 23:15:30 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2013-12-14 10:52:51 -0600 |
commit | 3b1b677b49af194313da766579e9fa1a021afd84 (patch) | |
tree | 475e9da703e745660d97df5e6827941bbea7595c | |
parent | cd427ead7e71bb5d7716f015b1f9753ee56a9b4e (diff) |
Speed up master key listing page
We were spending a lot of time getting the developer name for a given
key on this page, which involved sending one query per key ID. Use the
cache to our advantage here and save ourselves the "expensive" lookups.
This eliminates ~100 queries per page load.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | main/templatetags/pgp.py | 18 | ||||
-rw-r--r-- | templates/public/keys.html | 8 |
2 files changed, 17 insertions, 9 deletions
diff --git a/main/templatetags/pgp.py b/main/templatetags/pgp.py index e93e5bca..cc080439 100644 --- a/main/templatetags/pgp.py +++ b/main/templatetags/pgp.py @@ -3,6 +3,7 @@ from django.conf import settings from django.utils.html import conditional_escape from django.utils.safestring import mark_safe +from ..utils import cache_function from devel.models import DeveloperKey register = template.Library() @@ -42,15 +43,22 @@ def pgp_key_link(key_id, link_text=None): values = (url, format_key(key_id), link_text) return '<a href="%s" title="PGP key search for %s">%s</a>' % values -@register.simple_tag -def user_pgp_key_link(key_id): - normalized = key_id[-16:] + +@cache_function(1800) +def name_for_key(normalized): try: matching_key = DeveloperKey.objects.select_related( 'owner').get(key=normalized, owner_id__isnull=False) + return matching_key.owner.get_full_name() except DeveloperKey.DoesNotExist: - return pgp_key_link(key_id) - return pgp_key_link(key_id, matching_key.owner.get_full_name()) + return None + + +@register.simple_tag +def user_pgp_key_link(key_id): + normalized = key_id[-16:] + name = name_for_key(normalized) + return pgp_key_link(key_id, name) @register.filter(needs_autoescape=True) diff --git a/templates/public/keys.html b/templates/public/keys.html index c7272db3..54d52ab8 100644 --- a/templates/public/keys.html +++ b/templates/public/keys.html @@ -86,16 +86,16 @@ </tr> </thead> <tbody> - {% for user in active_users %} + {% for user in active_users %}{% with user_key=user.userprofile.pgp_key %} <tr> <th>{{ user.get_full_name }}</th> - <td>{% pgp_key_link user.userprofile.pgp_key %}</td> + <td>{% pgp_key_link user_key %}</td> {% spaceless %}{% for key in keys %} - {% signature_exists signatures key.pgp_key user.userprofile.pgp_key as signed %} + {% signature_exists signatures key.pgp_key user_key as signed %} <td class="signed-{{ signed|yesno }}">{{ signed|yesno|capfirst }}</td> {% endfor %}{% endspaceless %} </tr> - {% endfor %} + {% endwith %}{% endfor %} </tbody> </table> </div> |