Optimized last operations on counters

This commit is contained in:
NaNoMelo 2024-09-30 15:57:21 +02:00
parent 67af1485b3
commit 06eecfce40

View File

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