mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-09 11:19:08 +00:00
feat: 终端会话增加字段: cmd_amount(命令数量) (#11136)
* feat: 终端会话增加字段: command_amount(命令数量) * perf: 优化已产生会话的命令数量计算方式 * Update 0065_session_command_amount.py * Update session.py * Update session.py * perf: 优化会话命令数量的计算逻辑 * perf: 优化命令数量获取 --------- Co-authored-by: fangfang.dong <fangfang.dong@fit2cloud.com> Co-authored-by: Bai <baijiangjie@gmail.com>
This commit is contained in:
@@ -44,6 +44,7 @@ class Session(OrgModelMixin):
|
||||
date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True, default=timezone.now)
|
||||
date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)
|
||||
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
|
||||
cmd_amount = models.IntegerField(default=-1, verbose_name=_("Command amount"))
|
||||
|
||||
upload_to = 'replay'
|
||||
ACTIVE_CACHE_KEY_PREFIX = 'SESSION_ACTIVE_{}'
|
||||
@@ -177,6 +178,25 @@ class Session(OrgModelMixin):
|
||||
|
||||
@property
|
||||
def command_amount(self):
|
||||
if self.need_update_cmd_amount:
|
||||
cmd_amount = self.compute_command_amount()
|
||||
self.cmd_amount = cmd_amount
|
||||
self.save()
|
||||
elif self.need_compute_cmd_amount:
|
||||
cmd_amount = self.compute_command_amount()
|
||||
else:
|
||||
cmd_amount = self.cmd_amount
|
||||
return cmd_amount
|
||||
|
||||
@property
|
||||
def need_update_cmd_amount(self):
|
||||
return self.is_finished and self.need_compute_cmd_amount
|
||||
|
||||
@property
|
||||
def need_compute_cmd_amount(self):
|
||||
return self.cmd_amount == -1
|
||||
|
||||
def compute_command_amount(self):
|
||||
command_store = get_multi_command_storage()
|
||||
return command_store.count(session=str(self.id))
|
||||
|
||||
|
Reference in New Issue
Block a user