Skip to content

Commit

Permalink
perf: The command amount does not record operation logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong authored and BaiJiangJie committed Dec 18, 2024
1 parent 7f965b5 commit 829f867
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/audits/signal_handlers/operate_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
create_or_update_operate_log, get_instance_dict_from_cache
)
from audits.utils import model_to_dict_for_operate_log as model_to_dict
from common.const.signals import POST_ADD, POST_REMOVE, POST_CLEAR, SKIP_SIGNAL
from common.const.signals import POST_ADD, POST_REMOVE, POST_CLEAR, OP_LOG_SKIP_SIGNAL
from common.signals import django_ready
from jumpserver.utils import current_request
from ..const import MODELS_NEED_RECORD, ActionChoices
Expand Down Expand Up @@ -77,7 +77,7 @@ def signal_of_operate_log_whether_continue(
condition = True
if not instance:
condition = False
if instance and getattr(instance, SKIP_SIGNAL, False):
if instance and getattr(instance, OP_LOG_SKIP_SIGNAL, False):
condition = False
# 不记录组件的操作日志
user = current_request.user if current_request else None
Expand Down
2 changes: 1 addition & 1 deletion apps/common/const/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def m2m_signal_handler(action, instance, reverse, model, pk_set, using):
POST_PREFIX = 'post'
PRE_PREFIX = 'pre'

SKIP_SIGNAL = 'skip_signal'
OP_LOG_SKIP_SIGNAL = 'operate_log_skip_signal'
4 changes: 2 additions & 2 deletions apps/common/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _

from ..const.signals import SKIP_SIGNAL
from ..const.signals import OP_LOG_SKIP_SIGNAL


class ChoicesMixin:
Expand Down Expand Up @@ -83,7 +83,7 @@ def CASCADE_SIGNAL_SKIP(collector, field, sub_objs, using):
# 级联删除时,操作日志标记不保存,以免用户混淆
try:
for obj in sub_objs:
setattr(obj, SKIP_SIGNAL, True)
setattr(obj, OP_LOG_SKIP_SIGNAL, True)
except:
pass

Expand Down
4 changes: 2 additions & 2 deletions apps/terminal/models/component/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from common.const.signals import SKIP_SIGNAL
from common.const.signals import OP_LOG_SKIP_SIGNAL
from common.db.models import JMSBaseModel
from common.utils import get_logger, lazyproperty
from orgs.utils import tmp_to_root_org
Expand Down Expand Up @@ -160,7 +160,7 @@ def service_account(self):

def delete(self, using=None, keep_parents=False):
if self.user:
setattr(self.user, SKIP_SIGNAL, True)
setattr(self.user, OP_LOG_SKIP_SIGNAL, True)
self.user.delete()
self.name = self.name + '_' + uuid.uuid4().hex[:8]
self.user = None
Expand Down
2 changes: 2 additions & 0 deletions apps/terminal/models/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils.translation import gettext_lazy as _

from assets.models import Asset
from common.const.signals import OP_LOG_SKIP_SIGNAL
from common.utils import get_object_or_none, lazyproperty
from orgs.mixins.models import OrgModelMixin
from terminal.backends import get_multi_command_storage
Expand Down Expand Up @@ -221,6 +222,7 @@ def command_amount(self):
if self.need_update_cmd_amount:
cmd_amount = self.compute_command_amount()
self.cmd_amount = cmd_amount
setattr(self, OP_LOG_SKIP_SIGNAL, True)
self.save()
elif self.need_compute_cmd_amount:
cmd_amount = self.compute_command_amount()
Expand Down

0 comments on commit 829f867

Please sign in to comment.