Improve schedule filters before generating user calendar export (#4950)

Avoid checking all schedules in an organization when filtering user
events during export.
This should help with some slow requests we are noticing.
This commit is contained in:
Matias Bordese 2024-08-29 08:56:03 -03:00 committed by GitHub
parent 754fa8728e
commit f5be809b47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,6 +84,8 @@ class UserView(RateLimitHeadersMixin, ShortSerializerMixin, ReadOnlyModelViewSet
permission_classes=(IsAuthenticated,),
)
def schedule_export(self, request, pk):
schedules = OnCallSchedule.objects.filter(organization=self.request.auth.organization)
schedules = OnCallSchedule.objects.filter(organization=self.request.auth.organization).related_to_user(
self.request.user
)
export = user_ical_export(self.request.user, schedules)
return Response(export)