From a936092020f42e1bda57aa8f5d905c8b570f53a0 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Sat, 2 Apr 2022 13:26:18 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20es=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BC=98=E5=8C=96=20(#8020)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: feng626 <1304903146@qq.com> --- apps/terminal/backends/command/es.py | 37 ++++++++++++++-------------- apps/terminal/serializers/storage.py | 18 +++----------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/apps/terminal/backends/command/es.py b/apps/terminal/backends/command/es.py index d74ad3fa8..2e8a82c88 100644 --- a/apps/terminal/backends/command/es.py +++ b/apps/terminal/backends/command/es.py @@ -18,7 +18,6 @@ from common.utils import get_logger from common.exceptions import JMSException from .models import AbstractSessionCommand - logger = get_logger(__file__) @@ -27,7 +26,7 @@ class InvalidElasticsearch(JMSException): default_detail = _('Invalid elasticsearch config') -class CommandStore(): +class CommandStore(object): def __init__(self, config): hosts = config.get("HOSTS") kwargs = config.get("OTHER", {}) @@ -208,7 +207,7 @@ class CommandStore(): elif org_id in (real_default_org_id, ''): match.pop('org_id') should.append({ - 'bool':{ + 'bool': { 'must_not': [ { 'wildcard': {'org_id': '*'} @@ -226,20 +225,20 @@ class CommandStore(): ], 'should': should, 'filter': [ - { - 'term': {k: v} - } for k, v in exact.items() - ] + [ - { - 'range': { - 'timestamp': timestamp_range - } - } - ] + [ - { - 'ids': {k: v} - } for k, v in index.items() - ] + { + 'term': {k: v} + } for k, v in exact.items() + ] + [ + { + 'range': { + 'timestamp': timestamp_range + } + } + ] + [ + { + 'ids': {k: v} + } for k, v in index.items() + ] } }, } @@ -326,8 +325,8 @@ class QuerySet(DJQuerySet): def __getattribute__(self, item): if any(( - item.startswith('__'), - item in QuerySet.__dict__, + item.startswith('__'), + item in QuerySet.__dict__, )): return object.__getattribute__(self, item) diff --git a/apps/terminal/serializers/storage.py b/apps/terminal/serializers/storage.py index 2b21625bd..81c885862 100644 --- a/apps/terminal/serializers/storage.py +++ b/apps/terminal/serializers/storage.py @@ -13,8 +13,6 @@ from rest_framework.validators import UniqueValidator # Replay storage serializers # -------------------------- - - def replay_storage_endpoint_format_validator(endpoint): h = urlparse(endpoint) if h.path: @@ -116,9 +114,8 @@ class ReplayStorageTypeAzureSerializer(serializers.Serializer): label=_('Endpoint suffix'), allow_null=True, ) -# mapping - +# mapping replay_storage_type_serializer_classes_mapping = { const.ReplayStorageTypeChoices.s3.value: ReplayStorageTypeS3Serializer, const.ReplayStorageTypeChoices.ceph.value: ReplayStorageTypeCephSerializer, @@ -129,10 +126,9 @@ replay_storage_type_serializer_classes_mapping = { const.ReplayStorageTypeChoices.cos.value: ReplayStorageTypeCOSSerializer } + # Command storage serializers # --------------------------- - - def command_storage_es_host_format_validator(host): h = urlparse(host) default_error_msg = _('The address format is incorrect') @@ -151,7 +147,6 @@ def command_storage_es_host_format_validator(host): class CommandStorageTypeESSerializer(serializers.Serializer): - hosts_help_text = ''' Tip: If there are multiple hosts, use a comma (,) to separate them.
(eg: http://www.jumpserver.a.com:9100, http://www.jumpserver.b.com:9100) @@ -169,17 +164,14 @@ class CommandStorageTypeESSerializer(serializers.Serializer): source='OTHER.IGNORE_VERIFY_CERTS', allow_null=True, ) -# mapping - +# mapping command_storage_type_serializer_classes_mapping = { const.CommandStorageTypeChoices.es.value: CommandStorageTypeESSerializer } # BaseStorageSerializer - - class BaseStorageSerializer(serializers.ModelSerializer): storage_type_serializer_classes_mapping = {} meta = MethodSerializer() @@ -223,8 +215,6 @@ class BaseStorageSerializer(serializers.ModelSerializer): # CommandStorageSerializer - - class CommandStorageSerializer(BaseStorageSerializer): storage_type_serializer_classes_mapping = command_storage_type_serializer_classes_mapping @@ -236,8 +226,6 @@ class CommandStorageSerializer(BaseStorageSerializer): # ReplayStorageSerializer - - class ReplayStorageSerializer(BaseStorageSerializer): storage_type_serializer_classes_mapping = replay_storage_type_serializer_classes_mapping