Verified Commit 21206bbe authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Optimize SQL requests in OrderHistView

parent 0ae93fb8
......@@ -488,8 +488,23 @@ class OrderHistView(LoginRequiredMixin, ListView):
model = OrderItem
def get_queryset(self) -> "QuerySet[Order]":
orders = Order.objects.filter(user=self.request.user, ordered=True).order_by(
"-ordered_date"
orders = (
Order.objects.filter(
user=self.request.user,
ordered=True,
)
.order_by("-ordered_date")
.prefetch_related(
"items",
"items__item",
"items__pack_parent__item",
)
.select_related(
"user",
"user__contribution",
"payment",
"payment__lydia_request",
)
)
for order in orders:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment