#23771: Optimisation idea for Paginator object
-------------------------------------+-------------------------------------
Reporter: GP89 | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution:
Keywords: paginator | Triage Stage: Accepted
optimization performance |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Josh Smeaton):
Adding my +1 to this, as it makes it extremely difficult to optimise
readonly annotations in the admin. As an example:
{{{
class MyAdmin(admin.ModelAdmin):
list_display = ("f1", "f2", "related_count")
def related_count(self, obj):
return obj.related_count
def get_queryset(self, request):
return
super().get_queryset(request).annotate(related_count=Count("related"))
}}}
If QuerySet had a way to remove annotations like select_related(None) or
order_by(), then we could implement a Paginator like so:
{{{
class BetterCountPaginator(Paginator):
@cached_property
def count(self):
return self.object_list.annotate(None).count()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23771#comment:6>
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/062.9d0f6e8398e2db7fa893ab65407eebac%40djangoproject.com.