Improve DB efficiency for user settings (#6996)

- Prefetch related user
- Prevents 1+N issue
This commit is contained in:
Oliver 2024-04-11 10:05:20 +10:00 committed by GitHub
parent 1e0382c719
commit f61259e0d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -258,6 +258,13 @@ class UserSettingsList(SettingsList):
common.models.InvenTreeUserSetting.build_default_values(user=request.user)
return super().list(request, *args, **kwargs)
def get_queryset(self):
"""Return prefetched queryset."""
queryset = super().get_queryset()
queryset = queryset.prefetch_related('user')
return queryset
def filter_queryset(self, queryset):
"""Only list settings which apply to the current user."""
try: