﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4196	[patch] Use select_related() when retrieving a user profile	Matt Riggott	nobody	"To start with an example:

{{{
>>> from django.contrib.auth.models import User
>>> u = User.objects.get(pk=1)
>>> p = u.get_profile()
>>> p.user.username
'dave'
>>> from django.db import connection
>>> len(connection.queries)
3
}}}

Even though I'm dealing with two database objects (a User and its profile) three queries were executed.  The first to get the user, the second to get the profile, and the third to get the user again.

If [http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/models.py#L260 line 257 in django/contrib/auth/models.py] was changed to use {{{select_related}}} the database would only be hit twice.

It's a minor thing, but I thought I'd mention it.  You know, just in case you guys ran out of patches to test and such.

(If a user profile has lots of foreign key fields this could result in a lot of objects being created, which is why I've limited the depth to 1.)"		closed	Contrib apps	dev		wontfix			Design decision needed	1	0	0	0	0	0
