Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] queue_job_batch: Improve perf of counters #557

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions queue_job_batch/models/queue_job_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ def get_new_batch(self, name, **kwargs):
})
return self.sudo().create(vals).sudo(self.env.uid)

@api.depends('job_ids')
@api.depends("job_ids", "job_ids.state")
def _compute_job_count(self):
for record in self:
job_count = len(record.job_ids)
failed_job_count = len(record.job_ids.filtered(
lambda r: r.state == 'failed'
))
done_job_count = len(record.job_ids.filtered(
lambda r: r.state == 'done'
))
record.job_count = job_count
record.finished_job_count = done_job_count
record.failed_job_count = failed_job_count
record.completeness = done_job_count / max(1, job_count)
record.failed_percentage = failed_job_count / max(1, job_count)
jobs = record.job_ids
states = [r["state"] for r in jobs.read(["state"])]
simahawk marked this conversation as resolved.
Show resolved Hide resolved

total = len(jobs)
failed = states.count("failed")
done = states.count("done")

record.job_count = total
record.finished_job_count = done
record.failed_job_count = failed
record.completeness = done / max(1, total)
record.failed_percentage = failed / max(1, total)
Loading