From 12036f8c96b71d68c6e2d408bec3a412a9bdc6c2 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 20 Jul 2022 16:53:03 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20django=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/backends/command/es.py | 4 ++-- apps/terminal/backends/command/models.py | 15 --------------- apps/terminal/models/command.py | 17 +++++++++++++++-- requirements/requirements.txt | 2 +- requirements/rpm_pkg.sh | 3 ++- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/apps/terminal/backends/command/es.py b/apps/terminal/backends/command/es.py index 1387f6656..20602769c 100644 --- a/apps/terminal/backends/command/es.py +++ b/apps/terminal/backends/command/es.py @@ -18,7 +18,7 @@ from common.utils.common import lazyproperty from common.utils import get_logger from common.utils.timezone import local_now_date_display, utc_now from common.exceptions import JMSException -from .models import AbstractSessionCommand +from terminal.models import Command logger = get_logger(__file__) @@ -181,7 +181,7 @@ class CommandStore(object): item['_source'].update({'id': item['_id']}) source_data.append(item['_source']) - return AbstractSessionCommand.from_multi_dict(source_data) + return Command.from_multi_dict(source_data) def count(self, **query): body = self.get_query_body(**query) diff --git a/apps/terminal/backends/command/models.py b/apps/terminal/backends/command/models.py index 0a795b905..d6eb7a458 100644 --- a/apps/terminal/backends/command/models.py +++ b/apps/terminal/backends/command/models.py @@ -47,21 +47,6 @@ class AbstractSessionCommand(OrgModelMixin): risk_mapper = dict(cls.RISK_LEVEL_CHOICES) return risk_mapper.get(risk_level) - @classmethod - def from_dict(cls, d): - self = cls() - for k, v in d.items(): - setattr(self, k, v) - return self - - @classmethod - def from_multi_dict(cls, l): - commands = [] - for d in l: - command = cls.from_dict(d) - commands.append(command) - return commands - def to_dict(self): d = {} for field in self._meta.fields: diff --git a/apps/terminal/models/command.py b/apps/terminal/models/command.py index 3e94740ff..44edf013c 100644 --- a/apps/terminal/models/command.py +++ b/apps/terminal/models/command.py @@ -1,7 +1,5 @@ from __future__ import unicode_literals -import time - from django.db import models from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy as _ @@ -47,6 +45,21 @@ class Command(AbstractSessionCommand): cls.objects.bulk_create(commands) print(f'Create {len(commands)} commands of org ({org})') + @classmethod + def from_dict(cls, d): + self = cls() + for k, v in d.items(): + setattr(self, k, v) + return self + + @classmethod + def from_multi_dict(cls, l): + commands = [] + for d in l: + command = cls.from_dict(d) + commands.append(command) + return commands + class Meta: db_table = "terminal_command" ordering = ('-timestamp',) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 1dac6922d..75e397656 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -62,7 +62,7 @@ jsonfield2==4.0.0.post0 geoip2==4.5.0 ipip-ipdb==1.6.1 # Django environment -Django==3.1.14 +Django==3.2.14 django-bootstrap3==14.2.0 django-filter==2.4.0 django-formtools==2.2 diff --git a/requirements/rpm_pkg.sh b/requirements/rpm_pkg.sh index f48bd3ac8..b926690dc 100644 --- a/requirements/rpm_pkg.sh +++ b/requirements/rpm_pkg.sh @@ -1,4 +1,5 @@ #!/bin/bash yum -y install \ gcc-c++ sshpass mariadb-devel openldap-devel libxml2-devel \ - xmlsec1-devel xmlsec1-openssl-devel libtool-ltdl-devel + xmlsec1-devel xmlsec1-openssl-devel libtool-ltdl-devel \ + postgresql-devel