perf: 优化提示

pull/10032/head
ibuler 2023-03-22 14:56:20 +08:00
parent 180ded1773
commit ba076f6612
3 changed files with 14 additions and 5 deletions

View File

@ -8,7 +8,7 @@ def migrate_platform_charset(apps, schema_editor):
platform_model.objects.filter(charset='utf8').update(charset='utf-8')
def migrate_platform_protocol_required(apps, schema_editor):
def migrate_platform_protocol_primary(apps, schema_editor):
platform_model = apps.get_model('assets', 'Platform')
platforms = platform_model.objects.all()
@ -31,5 +31,5 @@ class Migration(migrations.Migration):
field=models.BooleanField(default=False, verbose_name='Primary'),
),
migrations.RunPython(migrate_platform_charset),
migrations.RunPython(migrate_platform_protocol_required),
migrations.RunPython(migrate_platform_protocol_primary),
]

View File

@ -132,6 +132,7 @@ class PlatformSerializer(WritableNestedModelSerializer):
if not primary:
protocols[0]['primary'] = True
protocols[0]['default'] = False
# 这里不设置不行write_nested 不使用 validated 中的
self.initial_data['protocols'] = protocols
return protocols

View File

@ -100,9 +100,17 @@ class JMSInventory:
host.update(self.make_proxy_command(gateway))
def asset_to_host(self, asset, account, automation, protocols, platform):
if protocols:
protocol = protocols[0].name
port = protocol[0].port
primary_protocol = [p for p in protocols if p.primary]
if len(primary_protocol) >= 1:
primary = primary_protocol[0]
elif protocols:
primary = protocols[0]
else:
primary = None
if primary:
protocol = primary.name
port = primary.port
else:
protocol = 'null'
port = 0