Skip to content

Commit

Permalink
Performance improvement for notifications API endpoint (#7154)
Browse files Browse the repository at this point in the history
* Prefecth notifications queryset

* Apply prefetch to detail endpoint also

* Improve prefetch fields
  • Loading branch information
SchrodingersGat authored May 21, 2024
1 parent 76b298c commit bb93c91
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/backend/InvenTree/common/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit bb93c91

Please sign in to comment.