#33095: Admin actions shown with zero results
-------------------------------------+-------------------------------------
Reporter: Richard Laager | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Richard Laager:
Old description:
> contrib/admin/views/main.py has this:
> {{{
> # Admin actions are shown if there is at least one entry
> # or if entries are not counted because show_full_result_count is
> disabled
> self.show_admin_actions = not self.show_full_result_count or
> bool(full_result_count)
> }}}
>
> This was changed in 17557d068c43bd61cdc6c18caf250ffa469414a1 for #8408.
>
> Is it intentional that the admin actions be shown if there are ''any rows
> in the table'' as opposed to ''any results on the page''? Put
> differently, if there are no results on the page, I can't do anything
> with the actions, right?
>
> It seems like this should use result_count (which is the number of
> filtered results) rather than full_result_count (which is the number of
> rows in the table):
> {{{
> # Admin actions are shown if there is at least one entry
> self.show_admin_actions = bool(result_count)
> }}}
New description:
contrib/admin/views/main.py has this:
{{{
# Admin actions are shown if there is at least one entry
# or if entries are not counted because show_full_result_count is
disabled
self.show_admin_actions = not self.show_full_result_count or
bool(full_result_count)
}}}
This was changed in 17557d068c43bd61cdc6c18caf250ffa469414a1 for #8408.
Is it intentional that the admin actions be shown if there are ''any rows
in the table'' as opposed to ''any results on the page''? Put differently,
if there are no results on the page, I can't do anything with the actions,
right?
It seems like this should use result_count (which is the number of
filtered results) rather than full_result_count (which is the number of
rows in the table):
{{{
# Admin actions are shown if there is at least one entry
self.show_admin_actions = bool(result_count)
}}}
Additionally, if the above is accepted, then the only use of
full_result_count is on the search page, which opens up another
opportunity to optimize. As discussed further in #8408, there are two
different SELECT COUNT(*) calls. One is for the paginator, which operates
on the filtered results and one is for full_result_count which is
unfiltered. The latter is only used once (if the above suggestion is
adopted), in contrib/admin/templates/admin/search_form.html.
So we could skip calculating full_result_count if there is no search being
done. Note that this is subtly different than if there are no filters; see
#22810 for why that is an issue.
Alternatively, if you want to be safe and not make assumptions about what
people might be doing with full_result_count, this also works:
full_result_count = lazy(self.root_queryset.count()). Then if it is never
evaluated, the query never runs. I've tested both approaches.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33095#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.5f6b82b45da7d5abf05dc38a13219b87%40djangoproject.com.