API: Prefetch customer in order list view (#3768)

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.
This commit is contained in:
Michael Stapelberg
2023-12-11 13:02:40 +01:00
committed by GitHub
parent f543cf2da5
commit c5ede32649

View File

@@ -222,6 +222,8 @@ class OrderViewSetMixin:
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