From 543dde57ab80968403a51c0c365a67649f1f86eb Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Tue, 19 Nov 2024 14:21:49 +0800 Subject: [PATCH] perf: modify average_time_cost calculation in job model --- apps/ops/models/job.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apps/ops/models/job.py b/apps/ops/models/job.py index 28169afd9..673548f75 100644 --- a/apps/ops/models/job.py +++ b/apps/ops/models/job.py @@ -188,11 +188,7 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin): @property def average_time_cost(self): - total_cost = 0 - finished_count = self.executions.filter(status__in=['success', 'failed']).count() - for execution in self.executions.filter(status__in=['success', 'failed']).all(): - total_cost += execution.time_cost - return total_cost / finished_count if finished_count else 0 + return self.last_execution.time_cost if self.last_execution else 0 def get_register_task(self): from ..tasks import run_ops_job