#19080 closed Cleanup/optimization (fixed)
ChangeList.get_queryset() automatically applies select_related() in a very "brute" way
Reported by: | Béres Botond | Owned by: | Tomek Paczkowski |
---|---|---|---|
Component: | contrib.admin | Version: | 1.4 |
Severity: | Normal | Keywords: | performance |
Cc: | tomek@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If there is a single related field from the listing model in list_display
, ChangeList.get_queryset
will apply select_related()
so it will join everything, with no depth or field limitations.
Combined with the fact that there's no documented way to clear that (#16856), it's quite undesirable behaviour.
In my opinion this could be resolved in 2 ways:
- Remove that .select_related() call altogether and let the developer choose the exact optimization if he is displaying related fields in the listing
- Optimize the select_related() call so that it's constructed exactly based on which fields appear in
list_display
Change History (7)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Oh wait, never mind. The list_select_related
attribute would in fact be ignored in your case.
I think your suggestion "2." would be too complex to implement and could be quite brittle.
I think "1." seems reasonable — it all depends if in most cases the developer would want to use select_related or not. It'd be good to provide a sane default that can be occasionally overridden. It'd be good to gather some anecdotal statistics on that. If it appears that using select_related
would in fact be a sane default, then I'd rather focus on enabling the clearing of the select_related
behavior (as discussed in #16856) for the time being.
Accepting this ticket on the basis that this is a valid issue that needs fixing.
comment:3 by , 11 years ago
I've added pull request for this ticket: https://github.com/django/django/pull/1245
It implements finer control over select_related, allowing setting this attribute to a tuple. Empty tuple disables select_related
and any other is passed as arguments to select_related
.
comment:4 by , 11 years ago
Cc: | added |
---|---|
Has patch: | set |
Owner: | changed from | to
Status: | new → assigned |
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Have you tried setting the
ModelAdmin.list_select_related
toFalse
? Does it solve your problem?