From 93932f1904fa7d47224d1a3c1a6d29f42a4bcce4 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 2 Feb 2023 20:10:48 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20(#9418)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 优化批量更新 * perf: 优化代码,减少 80%,依然可用 --------- Co-authored-by: ibuler --- apps/assets/serializers/asset/common.py | 4 ++-- apps/common/serializers/common.py | 10 ++++------ apps/common/serializers/mixin.py | 4 ++-- apps/orgs/mixins/serializers.py | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/assets/serializers/asset/common.py b/apps/assets/serializers/asset/common.py index e51c4558f..d4643d9ac 100644 --- a/apps/assets/serializers/asset/common.py +++ b/apps/assets/serializers/asset/common.py @@ -119,8 +119,8 @@ class AssetSerializer(BulkOrgResourceModelSerializer, WritableNestedModelSeriali 'nodes_display', 'accounts' ] read_only_fields = [ - 'category', 'type', 'connectivity', 'date_verified', - 'created_by', 'date_created' + 'category', 'type', 'connectivity', + 'date_verified', 'created_by', 'date_created' ] fields = fields_small + fields_fk + fields_m2m + read_only_fields extra_kwargs = { diff --git a/apps/common/serializers/common.py b/apps/common/serializers/common.py index 805aaa453..1515fe911 100644 --- a/apps/common/serializers/common.py +++ b/apps/common/serializers/common.py @@ -1,15 +1,13 @@ - +from django.utils.functional import cached_property +from django.utils.translation import gettext_lazy as _ +from drf_writable_nested.serializers import WritableNestedModelSerializer as NestedModelSerializer from rest_framework import serializers -from rest_framework.serializers import Serializer from rest_framework.serializers import ModelSerializer +from rest_framework.serializers import Serializer from rest_framework_bulk.serializers import BulkListSerializer -from django.utils.translation import gettext_lazy as _ -from django.utils.functional import cached_property -from drf_writable_nested.serializers import WritableNestedModelSerializer as NestedModelSerializer from .mixin import BulkListSerializerMixin, BulkSerializerMixin - __all__ = [ 'MethodSerializer', 'EmptySerializer', 'BulkModelSerializer', 'AdaptedBulkListSerializer', 'CeleryTaskExecutionSerializer', diff --git a/apps/common/serializers/mixin.py b/apps/common/serializers/mixin.py index 749a39820..734b6b4d9 100644 --- a/apps/common/serializers/mixin.py +++ b/apps/common/serializers/mixin.py @@ -1,4 +1,4 @@ -from collections import Iterable +from collections import Iterable, defaultdict from django.core.exceptions import ObjectDoesNotExist from django.db.models import NOT_PROVIDED @@ -362,7 +362,7 @@ class CommonModelSerializer(CommonSerializerMixin, serializers.ModelSerializer): class CommonBulkSerializerMixin(BulkSerializerMixin, CommonSerializerMixin): - pass + _save_kwargs = defaultdict(dict) class CommonBulkModelSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): diff --git a/apps/orgs/mixins/serializers.py b/apps/orgs/mixins/serializers.py index 7ff66cf59..e2e5a48a8 100644 --- a/apps/orgs/mixins/serializers.py +++ b/apps/orgs/mixins/serializers.py @@ -4,9 +4,9 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers from rest_framework.validators import UniqueTogetherValidator -from common.validators import ProjectUniqueValidator -from common.serializers import BulkSerializerMixin, CommonSerializerMixin, CommonModelSerializer, \ +from common.serializers import CommonModelSerializer, \ CommonBulkModelSerializer +from common.validators import ProjectUniqueValidator from ..utils import get_current_org_id_for_serializer __all__ = [