#34593 closed Cleanup/optimization (wontfix)
Django admin list does same Count query twice when there are no filters
Reported by: | Alex | Owned by: | Alex |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Simon Charette | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The issue is due to this code:
# Get the number of objects, with admin filters applied. result_count = paginator.count # First count() query # Get the total number of objects, with no admin filters applied. if self.model_admin.show_full_result_count: full_result_count = self.root_queryset.count() # Second count() query else: full_result_count = None
When the there are no filters, the same query is done for result_count
and full_result_count
and the value will always be the same.
Change History (11)
comment:1 by , 19 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 19 months ago
Has patch: | set |
---|
comment:4 by , 19 months ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Triage Stage: | Accepted → Unreviewed |
Closing as "wontfix" per Simon's comment.
comment:6 by , 13 months ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
Version: | 4.2 → dev |
Bug reopened since I think I've found a solution that actually avoids the extra count query when it's not needed.
comment:7 by , 13 months ago
Easy pickings: | unset |
---|
follow-up: 11 comment:8 by , 13 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I still have concerns. I appreciate you'd like to reopen the ticket, but please first start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, and follow triaging guidelines with regards to wontfix tickets.
comment:9 by , 13 months ago
Cc: | added |
---|
comment:10 by , 13 months ago
I share Mariusz concerns, I'm not sure it's worth trying to be extra clever here given the many hooks the admin exposes to configure returned results and the fact show_full_result_count = False
can disable the extra count entirely in cases where it's expensive enough to consider this option.
comment:11 by , 13 months ago
Replying to Mariusz Felisiak:
I still have concerns. I appreciate you'd like to reopen the ticket, but please first start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, and follow triaging guidelines with regards to wontfix tickets.
I didn't know of the mailing list. I continued the original discussion of the forum when the bug was initially opened, which according to the wontfix guidelines, it's one of the places where you can do it.
Next time I'll wait until I get more feedback (I didn't get much on the forum) or try the mailing list.Thanks for the feedback.
https://forum.djangoproject.com/t/django-admin-list-does-count-query-twice/21100
Thanks Alex 👍