Opened 19 months ago

Closed 13 months ago

Last modified 13 months ago

#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 David Sanders, 19 months ago

Triage Stage: UnreviewedAccepted

Thanks Alex,

I've assigned it to you as it sounded like you were interested in submitting a PR?

Version 0, edited 19 months ago by David Sanders (next)

comment:2 by Alex, 19 months ago

Has patch: set

comment:4 by Mariusz Felisiak, 19 months ago

Resolution: wontfix
Status: assignedclosed
Triage Stage: AcceptedUnreviewed

Closing as "wontfix" per Simon's comment.

comment:5 by GitHub <noreply@…>, 19 months ago

In 9d756afb:

Refs #34593 -- Commented that the extra count is necessary in ChangeList.get_results().

comment:6 by Alex, 13 months ago

Resolution: wontfix
Status: closednew
Version: 4.2dev

Bug reopened since I think I've found a solution that actually avoids the extra count query when it's not needed.

PR: https://github.com/django/django/pull/17568

comment:7 by Mariusz Felisiak, 13 months ago

Easy pickings: unset

comment:8 by Mariusz Felisiak, 13 months ago

Resolution: wontfix
Status: newclosed

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 Mariusz Felisiak, 13 months ago

Cc: Simon Charette added

comment:10 by Simon Charette, 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.

in reply to:  8 comment:11 by Alex, 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

Note: See TracTickets for help on using tickets.
Back to Top