changeset 308:4d086d2210b9

Fixing #141; cache badge ownership to reduce database hits when browsing forum topics.
author Brian Neal <bgneal@gmail.com>
date Sun, 16 Jan 2011 21:06:40 +0000
parents 7e19180b128d
children 8a0bae48b6ca
files gpp/bio/models.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/bio/models.py	Sun Jan 16 20:18:26 2011 +0000
+++ b/gpp/bio/models.py	Sun Jan 16 21:06:40 2011 +0000
@@ -114,8 +114,16 @@
     def badge_ownership(self):
         if hasattr(self, '_badges'):
             return self._badges
+
+        cache_key = 'badges-%s' % self.user.username
+        self._badges = cache.get(cache_key)
+        if self._badges is not None:
+            return self._badges
+
         self._badges = BadgeOwnership.objects.filter(profile=self).select_related(
                 "badge")
+
+        cache.set(cache_key, self._badges, 15 * 60)
         return self._badges
 
     def is_stranger(self):