1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Ditch some expensive prefetching for Hosts

This prefetching gets really expensive when we have a large number of
hosts, it's far less expensive to just go out and do subsequent queries
to pull this data in. (dropped aggregate query time down from ~2400ms to
~180ms)
This commit is contained in:
Akita Noek 2016-04-16 18:32:54 -04:00
parent a7f9eedb21
commit 74caa18cb5

View File

@ -365,10 +365,11 @@ class HostAccess(BaseAccess):
inv_qs = Inventory.accessible_objects(self.user, 'read_role')
group_qs = Group.accessible_objects(self.user, 'read_role')
qs = (self.model.objects.filter(inventory=inv_qs) | self.model.objects.filter(groups=group_qs)).distinct()
qs = qs.select_related('created_by', 'modified_by', 'inventory',
'last_job__job_template',
'last_job_host_summary__job')
return qs.prefetch_related('groups').all()
#qs = qs.select_related('created_by', 'modified_by', 'inventory',
# 'last_job__job_template',
# 'last_job_host_summary__job')
#return qs.prefetch_related('groups').all()
return qs
def can_read(self, obj):
return obj and any(self.user in grp.read_role for grp in obj.groups.all()) or self.user in obj.inventory.read_role