mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Improve performance of global order search
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
from django.db.models import Count, Q
|
||||
from django.db.models import Q
|
||||
from django.utils.functional import cached_property
|
||||
from django.views.generic import ListView
|
||||
|
||||
from pretix.base.models import Order
|
||||
from pretix.control.forms.filter import OrderSearchFilterForm
|
||||
from pretix.control.views import PaginationMixin
|
||||
from pretix.control.views import LargeResultSetPaginator, PaginationMixin
|
||||
|
||||
|
||||
class OrderSearch(PaginationMixin, ListView):
|
||||
model = Order
|
||||
paginator_class = LargeResultSetPaginator
|
||||
context_object_name = 'orders'
|
||||
template_name = 'pretixcontrol/search/orders.html'
|
||||
|
||||
@@ -22,7 +23,7 @@ class OrderSearch(PaginationMixin, ListView):
|
||||
return ctx
|
||||
|
||||
def get_queryset(self):
|
||||
qs = Order.objects.all().annotate(pcnt=Count('positions', distinct=True)).select_related('invoice_address')
|
||||
qs = Order.objects.select_related('invoice_address')
|
||||
if not self.request.user.is_superuser:
|
||||
qs = qs.filter(
|
||||
Q(event__organizer_id__in=self.request.user.teams.filter(
|
||||
@@ -34,7 +35,7 @@ class OrderSearch(PaginationMixin, ListView):
|
||||
if self.filter_form.is_valid():
|
||||
qs = self.filter_form.filter_qs(qs)
|
||||
|
||||
return qs.distinct().only(
|
||||
return qs.only(
|
||||
'id', 'invoice_address__name', 'code', 'event', 'email', 'datetime', 'total', 'status'
|
||||
).prefetch_related(
|
||||
'event', 'event__organizer'
|
||||
|
||||
Reference in New Issue
Block a user