perf: Optimize summary calculation

pull/14479/head
wangruidong 5 days ago committed by Bryan
parent 9771d3c817
commit b6a5854fa2

@ -37,6 +37,7 @@ class JobLogSerializer(JobExecutionSerializer):
class JobsAuditSerializer(JobSerializer):
material = serializers.ReadOnlyField(label=_("Command"))
summary = serializers.ReadOnlyField(label=_("Summary"))
crontab = serializers.ReadOnlyField(label=_("Execution cycle"))
class Meta(JobSerializer.Meta):
read_only_fields = [

@ -181,13 +181,9 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin):
@property
def summary(self):
summary = {
"total": 0,
"success": 0,
"total": self.executions.count(),
"success": self.executions.filter(status=JobStatus.success).count(),
}
for execution in self.executions.all():
summary["total"] += 1
if execution.is_success:
summary["success"] += 1
return summary
@property

Loading…
Cancel
Save