From bb93c915eeb06e353aec07385733467a3ad5683d Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 21 May 2024 22:24:33 +1000 Subject: [PATCH] Performance improvement for notifications API endpoint (#7154) * Prefecth notifications queryset * Apply prefetch to detail endpoint also * Improve prefetch fields --- src/backend/InvenTree/common/api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/backend/InvenTree/common/api.py b/src/backend/InvenTree/common/api.py index 52ef790c4a..821efd79d3 100644 --- a/src/backend/InvenTree/common/api.py +++ b/src/backend/InvenTree/common/api.py @@ -357,6 +357,22 @@ class NotificationMessageMixin: serializer_class = common.serializers.NotificationMessageSerializer 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): """List view for all notifications of the current user."""