Performance improvement for notifications API endpoint (#7154)

* Prefecth notifications queryset

* Apply prefetch to detail endpoint also

* Improve prefetch fields
This commit is contained in:
Oliver 2024-05-21 22:24:33 +10:00 committed by GitHub
parent 76b298c43e
commit bb93c915ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -357,6 +357,22 @@ class NotificationMessageMixin:
serializer_class = common.serializers.NotificationMessageSerializer serializer_class = common.serializers.NotificationMessageSerializer
permission_classes = [UserSettingsPermissions] permission_classes = [UserSettingsPermissions]
def get_queryset(self):
"""Return prefetched queryset."""
queryset = (
super()
.get_queryset()
.prefetch_related(
'source_content_type',
'source_object',
'target_content_type',
'target_object',
'user',
)
)
return queryset
class NotificationList(NotificationMessageMixin, BulkDeleteMixin, ListAPI): class NotificationList(NotificationMessageMixin, BulkDeleteMixin, ListAPI):
"""List view for all notifications of the current user.""" """List view for all notifications of the current user."""