1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 18:21:12 +03:00

Optimized /api/v1/hosts/

This commit is contained in:
Akita Noek 2016-04-25 09:06:40 -04:00
parent 754f8546a6
commit 8e4d013342

View File

@ -379,12 +379,16 @@ class HostAccess(BaseAccess):
def get_queryset(self): def get_queryset(self):
inv_qs = Inventory.accessible_objects(self.user, 'read_role') inv_qs = Inventory.accessible_objects(self.user, 'read_role')
group_qs = Group.accessible_objects(self.user, 'read_role') group_qs = Group.accessible_objects(self.user, 'read_role').exclude(inventory__in=inv_qs)
qs = (self.model.objects.filter(inventory=inv_qs) | self.model.objects.filter(groups=group_qs)).distinct() if group_qs.count():
#qs = qs.select_related('created_by', 'modified_by', 'inventory', qs = self.model.objects.filter(Q(inventory__in=inv_qs) | Q(groups__in=group_qs))
# 'last_job__job_template', else:
# 'last_job_host_summary__job') qs = self.model.objects.filter(inventory__in=inv_qs)
#return qs.prefetch_related('groups').all()
qs = qs.select_related('created_by', 'modified_by', 'inventory',
'last_job__job_template',
'last_job_host_summary__job')
qs =qs.prefetch_related('groups').all()
return qs return qs
def can_read(self, obj): def can_read(self, obj):
@ -491,7 +495,7 @@ class InventorySourceAccess(BaseAccess):
def get_queryset(self): def get_queryset(self):
qs = self.model.objects.all() qs = self.model.objects.all()
qs = qs.select_related('created_by', 'modified_by', 'group', 'inventory') qs = qs.select_related('created_by', 'modified_by', 'group', 'inventory')
inventory_ids = set(self.user.get_queryset(Inventory).values_list('id', flat=True)) inventory_ids = self.user.get_queryset(Inventory)
return qs.filter(Q(inventory_id__in=inventory_ids) | return qs.filter(Q(inventory_id__in=inventory_ids) |
Q(group__inventory_id__in=inventory_ids)) Q(group__inventory_id__in=inventory_ids))