perf: 接口 /api/v1/assets/label/ sql优化

pull/10761/head
fangfang.dong 2023-06-18 20:26:19 +08:00
parent 09f7ddd28a
commit 39ba52e4de
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