From d1b807bd8b8131fa0d0000778dfb4a25b1b1c098 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 23 Feb 2023 16:14:24 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20account=20asset=20?= =?UTF-8?q?auto=5Finfo=20=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/accounts/serializers/account/account.py | 2 +- apps/assets/serializers/asset/common.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/accounts/serializers/account/account.py b/apps/accounts/serializers/account/account.py index 42fc8f898..a06a11fd6 100644 --- a/apps/accounts/serializers/account/account.py +++ b/apps/accounts/serializers/account/account.py @@ -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 diff --git a/apps/assets/serializers/asset/common.py b/apps/assets/serializers/asset/common.py index c5a9ed02d..c4f2a5da7 100644 --- a/apps/assets/serializers/asset/common.py +++ b/apps/assets/serializers/asset/common.py @@ -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