Mercurial > public > sg101
comparison gpp/bio/models.py @ 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 | 39664e661c69 |
children | 000c006fee97 |
comparison
equal
deleted
inserted
replaced
307:7e19180b128d | 308:4d086d2210b9 |
---|---|
112 return ('bio-view_profile', (), {'username': self.user.username}) | 112 return ('bio-view_profile', (), {'username': self.user.username}) |
113 | 113 |
114 def badge_ownership(self): | 114 def badge_ownership(self): |
115 if hasattr(self, '_badges'): | 115 if hasattr(self, '_badges'): |
116 return self._badges | 116 return self._badges |
117 | |
118 cache_key = 'badges-%s' % self.user.username | |
119 self._badges = cache.get(cache_key) | |
120 if self._badges is not None: | |
121 return self._badges | |
122 | |
117 self._badges = BadgeOwnership.objects.filter(profile=self).select_related( | 123 self._badges = BadgeOwnership.objects.filter(profile=self).select_related( |
118 "badge") | 124 "badge") |
125 | |
126 cache.set(cache_key, self._badges, 15 * 60) | |
119 return self._badges | 127 return self._badges |
120 | 128 |
121 def is_stranger(self): | 129 def is_stranger(self): |
122 """Returns True if this user profile status is STA_STRANGER.""" | 130 """Returns True if this user profile status is STA_STRANGER.""" |
123 return self.status == STA_STRANGER | 131 return self.status == STA_STRANGER |