From 7a8eb69cae1e1b35b8ca3630c665678e2cae117e Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Fri, 21 Jun 2019 10:04:38 -0400 Subject: Prefetches Collaborators Prefetches collaborators to further reduce database accesses Change-Id: I5a976c4e17e20ca463576178371f70e59551b576 Signed-off-by: Parker Berberian --- dashboard/src/booking/stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dashboard/src/booking') diff --git a/dashboard/src/booking/stats.py b/dashboard/src/booking/stats.py index 62ba648..383723a 100644 --- a/dashboard/src/booking/stats.py +++ b/dashboard/src/booking/stats.py @@ -32,7 +32,7 @@ class StatisticsManager(object): now = datetime.datetime.now(pytz.utc) delta = datetime.timedelta(days=span) end = now - delta - bookings = Booking.objects.filter(start__lte=now, end__gte=end) + bookings = Booking.objects.filter(start__lte=now, end__gte=end).prefetch_related("collaborators") for booking in bookings: # collect data from each booking user_list = [u.pk for u in booking.collaborators.all()] user_list.append(booking.owner.pk) -- cgit 1.2.3-korg