Merge pull request #851 from ae-utbm/841-sales-selection-performance

841 sales selection performance
This commit is contained in:
thomas girod 2024-09-30 16:07:19 +02:00 committed by GitHub
commit 3f2327dee4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1173,12 +1173,16 @@ class CounterLastOperationsView(CounterTabsMixin, CanViewMixin, DetailView):
threshold = timezone.now() - timedelta(
minutes=settings.SITH_LAST_OPERATIONS_LIMIT
)
kwargs["last_refillings"] = self.object.refillings.filter(
date__gte=threshold
).order_by("-id")[:20]
kwargs["last_sellings"] = self.object.sellings.filter(
date__gte=threshold
).order_by("-id")[:20]
kwargs["last_refillings"] = (
self.object.refillings.filter(date__gte=threshold)
.select_related("operator", "customer__user")
.order_by("-id")[:20]
)
kwargs["last_sellings"] = (
self.object.sellings.filter(date__gte=threshold)
.select_related("seller", "customer__user")
.order_by("-id")[:20]
)
return kwargs