Skip to content

Commit

Permalink
API: Prefetch customer in order list view (#3768)
Browse files Browse the repository at this point in the history
Before this change, each order row needed an additional database query just to
resolve the customer id (integer) to customer identifier (string).

With this change, django does a database JOIN.
  • Loading branch information
stapelberg committed Dec 11, 2023
1 parent f543cf2 commit c5ede32
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pretix/api/views/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def get_queryset(self):
qs = qs.prefetch_related('refunds', 'refunds__payment')
if 'invoice_address' not in self.request.GET.getlist('exclude'):
qs = qs.select_related('invoice_address')
if 'customer' not in self.request.GET.getlist('exclude'):
qs = qs.select_related('customer')

qs = qs.prefetch_related(self._positions_prefetch(self.request))
return qs
Expand Down

0 comments on commit c5ede32

Please sign in to comment.