From 77569c554b8f08c6e14d008b6ad040913066bf28 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 25 Jan 2024 10:59:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=8E=BB=E6=8E=89=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9A=84=E9=BB=98=E8=AE=A4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/asset/asset.py | 1 + apps/assets/migrations/0109_alter_asset_options.py | 2 +- apps/assets/models/asset/common.py | 2 +- apps/perms/api/user_permission/assets.py | 3 +++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/assets/api/asset/asset.py b/apps/assets/api/asset/asset.py index b6e532b36..0f66d4b9a 100644 --- a/apps/assets/api/asset/asset.py +++ b/apps/assets/api/asset/asset.py @@ -92,6 +92,7 @@ class AssetViewSet(SuggestionMixin, OrgBulkModelViewSet): model = Asset filterset_class = AssetFilterSet search_fields = ("name", "address", "comment") + ordering = ('name',) ordering_fields = ('name', 'address', 'connectivity', 'platform', 'date_updated', 'date_created') serializer_classes = ( ("default", serializers.AssetSerializer), diff --git a/apps/assets/migrations/0109_alter_asset_options.py b/apps/assets/migrations/0109_alter_asset_options.py index 4a1c93a15..9140eff74 100644 --- a/apps/assets/migrations/0109_alter_asset_options.py +++ b/apps/assets/migrations/0109_alter_asset_options.py @@ -12,6 +12,6 @@ class Migration(migrations.Migration): operations = [ migrations.AlterModelOptions( name='asset', - options={'ordering': ['name'], 'permissions': [('refresh_assethardwareinfo', 'Can refresh asset hardware info'), ('test_assetconnectivity', 'Can test asset connectivity'), ('match_asset', 'Can match asset'), ('change_assetnodes', 'Can change asset nodes')], 'verbose_name': 'Asset'}, + options={'ordering': [], 'permissions': [('refresh_assethardwareinfo', 'Can refresh asset hardware info'), ('test_assetconnectivity', 'Can test asset connectivity'), ('match_asset', 'Can match asset'), ('change_assetnodes', 'Can change asset nodes')], 'verbose_name': 'Asset'}, ), ] diff --git a/apps/assets/models/asset/common.py b/apps/assets/models/asset/common.py index 558164df6..7d3fb5fd2 100644 --- a/apps/assets/models/asset/common.py +++ b/apps/assets/models/asset/common.py @@ -348,7 +348,7 @@ class Asset(NodesRelationMixin, LabeledMixin, AbsConnectivity, JSONFilterMixin, class Meta: unique_together = [('org_id', 'name')] verbose_name = _("Asset") - ordering = ["name", ] + ordering = [] permissions = [ ('refresh_assethardwareinfo', _('Can refresh asset hardware info')), ('test_assetconnectivity', _('Can test asset connectivity')), diff --git a/apps/perms/api/user_permission/assets.py b/apps/perms/api/user_permission/assets.py index b21604d5a..5456af1e3 100644 --- a/apps/perms/api/user_permission/assets.py +++ b/apps/perms/api/user_permission/assets.py @@ -1,5 +1,6 @@ import abc +from django.conf import settings from rest_framework.generics import ListAPIView, RetrieveAPIView from assets.api.asset.asset import AssetFilterSet @@ -47,6 +48,8 @@ class BaseUserPermedAssetsApi(SelfOrPKUserMixin, ListAPIView): def get_queryset(self): if getattr(self, 'swagger_fake_view', False): return Asset.objects.none() + if settings.ASSET_SIZE == 'small': + self.ordering = ['name'] assets = self.get_assets() assets = self.serializer_class.setup_eager_loading(assets) return assets