perf: 修改 sftp 的一些处理

pull/11106/head
ibuler 1 year ago committed by Bryan
parent 114645732a
commit 3b6c2fc0c0

@ -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
},

Loading…
Cancel
Save