perf: 修改 account asset auto_info 返回

pull/9718/head
ibuler 2 years ago
parent 3ee2bfce9a
commit d1b807bd8b

@ -119,7 +119,7 @@ class AccountSerializer(AccountSerializerCreateMixin, BaseAccountSerializer):
def setup_eager_loading(cls, queryset):
""" Perform necessary eager loading of data. """
queryset = queryset \
.prefetch_related('asset', 'asset__platform')
.prefetch_related('asset', 'asset__platform', 'asset__platform__automation')
return queryset

@ -136,6 +136,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer, WritableNestedModelSeriali
read_only_fields = [
'category', 'type', 'connectivity',
'date_verified', 'created_by', 'date_created',
'auto_info',
]
fields = fields_small + fields_fk + fields_m2m + read_only_fields
extra_kwargs = {
@ -182,10 +183,10 @@ class AssetSerializer(BulkOrgResourceModelSerializer, WritableNestedModelSeriali
@classmethod
def setup_eager_loading(cls, queryset):
""" Perform necessary eager loading of data. """
queryset = queryset.prefetch_related('domain', 'platform') \
queryset = queryset.prefetch_related('domain', 'nodes', 'labels', 'protocols') \
.prefetch_related('platform', 'platform__automation') \
.annotate(category=F("platform__category")) \
.annotate(type=F("platform__type"))
queryset = queryset.prefetch_related('nodes', 'labels', 'protocols')
return queryset
@staticmethod

Loading…
Cancel
Save