Fixed #8660 -- Small database query optimisation in User.get_profile.

When calling User.get_profile(), we now tell the profile object about the
related User object right away. This can save a database lookup later if
something in the user profile object wants to refer to the user object.

Patch from Mike Malone.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9152 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-10-05 12:07:10 +00:00
parent 40904d0404
commit 2f0be0faae
1 changed files with 1 additions and 0 deletions

View File

@ -291,6 +291,7 @@ class User(models.Model):
app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
model = models.get_model(app_label, model_name) model = models.get_model(app_label, model_name)
self._profile_cache = model._default_manager.get(user__id__exact=self.id) self._profile_cache = model._default_manager.get(user__id__exact=self.id)
self._profile_cache.user = self
except (ImportError, ImproperlyConfigured): except (ImportError, ImproperlyConfigured):
raise SiteProfileNotAvailable raise SiteProfileNotAvailable
return self._profile_cache return self._profile_cache