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

Split job-end host update into 2 queries to be slightly more efficient #14268

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
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
10 changes: 3 additions & 7 deletions awx/main/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,15 @@ def _update_host_summary_from_stats(self, hostnames):
JobHostSummary.objects.bulk_create(summaries.values())

# update the last_job_id and last_job_host_summary_id
# in single queries
host_mapping = dict((summary['host_id'], summary['id']) for summary in JobHostSummary.objects.filter(job_id=job.id).values('id', 'host_id'))
Host.objects.filter(id__in=host_mapping.keys()).update(last_job_id=job.id)

updated_hosts = set()
for h in all_hosts:
# if the hostname *shows up* in the playbook_on_stats event
if h.name in hostnames:
h.last_job_id = job.id
updated_hosts.add(h)
if h.id in host_mapping:
h.last_job_host_summary_id = host_mapping[h.id]
updated_hosts.add(h)

Host.objects.bulk_update(list(updated_hosts), ['last_job_id', 'last_job_host_summary_id'], batch_size=100)
Host.objects.bulk_update(list(updated_hosts), ['last_job_host_summary_id'], batch_size=100)

# Create/update Host Metrics
self._update_host_metrics(updated_hosts_list)
Expand Down
Loading