mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
optimize a slow query in inventory script generation
if we don't preload this column, Django needs it, and so it generates one query per-host (!!!) to get it. For large (10k+ host) inventories, this is incredibly slow. see: https://github.com/ansible/awx/issues/3214
This commit is contained in:
parent
570283fba2
commit
e245e50ee4
@ -239,7 +239,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
||||
hosts_kw = dict()
|
||||
if not show_all:
|
||||
hosts_kw['enabled'] = True
|
||||
fetch_fields = ['name', 'id', 'variables']
|
||||
fetch_fields = ['name', 'id', 'variables', 'inventory_id']
|
||||
if towervars:
|
||||
fetch_fields.append('enabled')
|
||||
hosts = self.hosts.filter(**hosts_kw).order_by('name').only(*fetch_fields)
|
||||
|
||||
@ -805,7 +805,10 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana
|
||||
def get_notification_friendly_name(self):
|
||||
return "Job"
|
||||
|
||||
def _get_inventory_hosts(self, only=['name', 'ansible_facts', 'ansible_facts_modified', 'modified',]):
|
||||
def _get_inventory_hosts(
|
||||
self,
|
||||
only=['name', 'ansible_facts', 'ansible_facts_modified', 'modified', 'inventory_id']
|
||||
):
|
||||
if not self.inventory:
|
||||
return []
|
||||
return self.inventory.hosts.only(*only)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user