mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 01:47:31 -02: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:
@@ -239,7 +239,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
|||||||
hosts_kw = dict()
|
hosts_kw = dict()
|
||||||
if not show_all:
|
if not show_all:
|
||||||
hosts_kw['enabled'] = True
|
hosts_kw['enabled'] = True
|
||||||
fetch_fields = ['name', 'id', 'variables']
|
fetch_fields = ['name', 'id', 'variables', 'inventory_id']
|
||||||
if towervars:
|
if towervars:
|
||||||
fetch_fields.append('enabled')
|
fetch_fields.append('enabled')
|
||||||
hosts = self.hosts.filter(**hosts_kw).order_by('name').only(*fetch_fields)
|
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):
|
def get_notification_friendly_name(self):
|
||||||
return "Job"
|
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:
|
if not self.inventory:
|
||||||
return []
|
return []
|
||||||
return self.inventory.hosts.only(*only)
|
return self.inventory.hosts.only(*only)
|
||||||
|
|||||||
Reference in New Issue
Block a user