Merge pull request #10175 from AlanCoding/only_have_eyes_for_you

Add more fields to .only since they get referenced

SUMMARY
Fixes a performance bottleneck when saving playbook_on_stats for jobs that use --limit against a small number of hosts while it has a large number in the inventory.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

API

ADDITIONAL INFORMATION
'tis the problem with .only(), that only the developer who wrote the queryset remembers that the other fields cannot be referenced except at the cost of another query
https://github.com/ansible/awx/pull/7352/files

Reviewed-by: Chris Meyers <None>
Reviewed-by: Alan Rominger <arominge@redhat.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-05-13 14:44:33 +00:00 committed by GitHub
commit d477f04d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -511,7 +511,7 @@ class JobEvent(BasePlaybookEvent):
from awx.main.models import Host, JobHostSummary # circular import
all_hosts = Host.objects.filter(pk__in=self.host_map.values()).only('id')
all_hosts = Host.objects.filter(pk__in=self.host_map.values()).only('id', 'name')
existing_host_ids = set(h.id for h in all_hosts)
summaries = dict()