Merge pull request #10761 from jumpserver/pr@dev@perf_assets_label

perf: 接口 /api/v1/assets/label/ sql优化
pull/10770/head
老广 2023-06-19 10:24:52 +08:00 committed by GitHub
commit 618ee0b2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -38,5 +38,6 @@ class LabelViewSet(OrgBulkModelViewSet):
return super().list(request, *args, **kwargs)
def get_queryset(self):
self.queryset = Label.objects.annotate(asset_count=Count("assets"))
self.queryset = Label.objects.prefetch_related(
'assets').annotate(asset_count=Count("assets"))
return self.queryset