Fixed #2189 -- Optimized auth.User.get_all_permissions() to use select_related behind the scenes to avoid multiple queries. Thanks, konrad@gwu.edu

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3162 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-06-20 03:08:48 +00:00
parent 496d651546
commit 551a0272e6
2 changed files with 2 additions and 1 deletions

View File

@ -74,6 +74,7 @@ answer newbie questions, and generally made Django that much better:
Cameron Knight (ckknight)
Bruce Kroeze <http://coderseye.com/>
Joseph Kocherhans
konrad@gwu.edu
lakin.wecker@gmail.com
Stuart Langridge <http://www.kryogenix.org/>
Eugene Lazutkin <http://lazutkin.com/blog/>

View File

@ -160,7 +160,7 @@ class User(models.Model):
def get_all_permissions(self):
if not hasattr(self, '_perm_cache'):
import sets
self._perm_cache = sets.Set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.all()])
self._perm_cache = sets.Set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.user_permissions.select_related()])
self._perm_cache.update(self.get_group_permissions())
return self._perm_cache