From 74caa18cb5dc20b7d6e03b7823c36bebf23db4c2 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Sat, 16 Apr 2016 18:32:54 -0400 Subject: [PATCH] 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) --- awx/main/access.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/awx/main/access.py b/awx/main/access.py index 1c49bb7e4d..10df3b4e63 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -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