From 3b6c2fc0c051dc5095d670c7a6fc1128baa01f33 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 26 Jul 2023 19:15:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20sftp=20=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/mixin.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/apps/assets/api/mixin.py b/apps/assets/api/mixin.py index 2cd928605..7d3c1c7a8 100644 --- a/apps/assets/api/mixin.py +++ b/apps/assets/api/mixin.py @@ -2,7 +2,7 @@ from typing import List from rest_framework.request import Request -from assets.models import Node, PlatformProtocol, Protocol +from assets.models import Node, Protocol from assets.utils import get_node_from_request, is_query_node_all_assets from common.utils import lazyproperty, timeit @@ -42,7 +42,7 @@ class SerializeToTreeNodeMixin: 'name': _name(node), 'title': _name(node), 'pId': node.parent_key, - 'isParent': True, + 'isParent': node.assets_amount > 0, 'open': _open(node), 'meta': { 'data': { @@ -70,25 +70,18 @@ class SerializeToTreeNodeMixin: @timeit def serialize_assets(self, assets, node_key=None, pid=None): - sftp_enabled_platform = PlatformProtocol.objects \ - .filter(name='ssh', setting__sftp_enabled=True) \ - .values_list('platform', flat=True) \ - .distinct() if node_key is None: get_pid = lambda asset: getattr(asset, 'parent_key', '') else: get_pid = lambda asset: node_key - ssh_asset_ids = [ - str(i) for i in - Protocol.objects.filter(name='ssh').values_list('asset_id', flat=True) - ] + sftp_asset_ids = Protocol.objects.filter(name='sftp') \ + .values_list('asset_id', flat=True) + sftp_asset_ids = list(sftp_asset_ids) data = [ { 'id': str(asset.id), 'name': asset.name, - 'title': - f'{asset.address}\n{asset.comment}' - if asset.comment else asset.address, + 'title': f'{asset.address}\n{asset.comment}', 'pId': pid or get_pid(asset), 'isParent': False, 'open': False, @@ -99,8 +92,7 @@ class SerializeToTreeNodeMixin: 'data': { 'platform_type': asset.platform.type, 'org_name': asset.org_name, - 'sftp': (asset.platform_id in sftp_enabled_platform) \ - and (str(asset.id) in ssh_asset_ids), + 'sftp': asset.id in sftp_asset_ids, 'name': asset.name, 'address': asset.address },