# HG changeset patch # User Brian Neal # Date 1295212000 0 # Node ID 4d086d2210b9dc863a6e9c6450a78a523a7f06e5 # Parent 7e19180b128df2f209900b79d1e7b5d022b08973 Fixing #141; cache badge ownership to reduce database hits when browsing forum topics. diff -r 7e19180b128d -r 4d086d2210b9 gpp/bio/models.py --- 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):