mirror of
https://github.com/ansible/awx.git
synced 2026-03-03 17:51:06 -03:30
further optimize job host summary queries
This commit is contained in:
committed by
Elijah DeLee
parent
59d457207c
commit
d85df2e4a1
@@ -490,12 +490,15 @@ class JobEvent(BasePlaybookEvent):
|
|||||||
job = self.job
|
job = self.job
|
||||||
|
|
||||||
from awx.main.models import Host, JobHostSummary # circular import
|
from awx.main.models import Host, JobHostSummary # circular import
|
||||||
existing = Host.objects.filter(id__in=self.host_map.values()).values_list('id', flat=True)
|
all_hosts = Host.objects.filter(
|
||||||
|
pk__in=self.host_map.values()
|
||||||
|
).only('id')
|
||||||
|
existing_host_ids = set(h.id for h in all_hosts)
|
||||||
|
|
||||||
summaries = dict()
|
summaries = dict()
|
||||||
for host in hostnames:
|
for host in hostnames:
|
||||||
host_id = self.host_map.get(host, None)
|
host_id = self.host_map.get(host, None)
|
||||||
if host_id not in existing:
|
if host_id not in existing_host_ids:
|
||||||
host_id = None
|
host_id = None
|
||||||
host_stats = {}
|
host_stats = {}
|
||||||
for stat in ('changed', 'dark', 'failures', 'ignored', 'ok', 'processed', 'rescued', 'skipped'):
|
for stat in ('changed', 'dark', 'failures', 'ignored', 'ok', 'processed', 'rescued', 'skipped'):
|
||||||
@@ -514,12 +517,9 @@ class JobEvent(BasePlaybookEvent):
|
|||||||
# update the last_job_id and last_job_host_summary_id
|
# update the last_job_id and last_job_host_summary_id
|
||||||
# in single queries
|
# in single queries
|
||||||
host_mapping = dict(
|
host_mapping = dict(
|
||||||
(summary['host'], summary['id'])
|
(summary['host_id'], summary['id'])
|
||||||
for summary in JobHostSummary.objects.filter(job_id=job.id).values('id', 'host')
|
for summary in JobHostSummary.objects.filter(job_id=job.id).values('id', 'host_id')
|
||||||
)
|
)
|
||||||
all_hosts = Host.objects.filter(
|
|
||||||
pk__in=host_mapping.keys()
|
|
||||||
).only('id')
|
|
||||||
for h in all_hosts:
|
for h in all_hosts:
|
||||||
h.last_job_id = job.id
|
h.last_job_id = job.id
|
||||||
if h.id in host_mapping:
|
if h.id in host_mapping:
|
||||||
|
|||||||
Reference in New Issue
Block a user