Admin generates a query burst on ForeignKey with null = True
|Reported by:||piro||Owned by:||Daniel Roseman|
|Severity:||Normal||Keywords:||admin database performance|
|Cc:||semenov@…, Brillgen Developers, erik.wognsen@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When the The admin loads a list of objects to display the change list, it is supposed to use select_related() to fetch ForeignKey fields in the display list.
Because it uses the form select_related() without the filed name, the records are not fetched if the property has null=True. This generates a burst of up of 100 query to display the admin page for such a model.
Attached there is a preliminary patch to fix the issue. It is probably to be improved as it doesn't kick in if the model is configured with list_select_related=True or if select_related() was already called on the query.
Change History (14)
comment:2 Changed 6 years ago by
|Owner:||changed from nobody to Daniel Roseman|
|Status:||new → assigned|
|Triage Stage:||Unreviewed → Accepted|
comment:6 Changed 6 years ago by
|Patch needs improvement:||set|