perf: change asset

pull/8873/head
ibuler 2022-08-05 16:17:45 +08:00
parent 196e38897f
commit 88d4bf932c
2 changed files with 3 additions and 18 deletions

View File

@ -97,25 +97,10 @@ class AssetSerializer(CategoryDisplayMixin, OrgResourceModelSerializerMixin):
@classmethod
def setup_eager_loading(cls, queryset):
""" Perform necessary eager loading of data. """
queryset = queryset.prefetch_related('domain', 'platform')
queryset = queryset.prefetch_related('domain', 'platform', 'protocols')
queryset = queryset.prefetch_related('nodes', 'labels')
return queryset
def compatible_with_old_protocol(self, validated_data):
protocols_data = validated_data.pop("protocols", [])
# 兼容老的api
name = validated_data.get("protocol")
port = validated_data.get("port")
if not protocols_data and name and port:
protocols_data.insert(0, '/'.join([name, str(port)]))
elif not name and not port and protocols_data:
protocol = protocols_data[0].split('/')
validated_data["protocol"] = protocol[0]
validated_data["port"] = int(protocol[1])
if protocols_data:
validated_data["protocols"] = protocols_data
def perform_nodes_display_create(self, instance, nodes_display):
if not nodes_display:
return

View File

@ -6,6 +6,6 @@ import subprocess
if __name__ == '__main__':
subprocess.call('python3 jms start all', shell=True,
stdin=sys.stdin, stdout=sys.stdout)
kwargs = dict(shell=True, stdin=sys.stdin, stdout=sys.stdout)
subprocess.call('python3 jms start all', **kwargs)