1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #4381 from AlanCoding/prefetch_optimizing

Use prefetch_related for several more things
This commit is contained in:
Alan Rominger 2016-12-12 10:22:43 -05:00 committed by GitHub
commit 39e5765f12
2 changed files with 5 additions and 0 deletions

View File

@ -1024,6 +1024,7 @@ class ProjectList(ListCreateAPIView):
'update_role', 'update_role',
'read_role', 'read_role',
) )
projects_qs = projects_qs.prefetch_related('last_job', 'created_by')
return projects_qs return projects_qs
@ -1579,6 +1580,7 @@ class InventoryList(ListCreateAPIView):
def get_queryset(self): def get_queryset(self):
qs = Inventory.accessible_objects(self.request.user, 'read_role') qs = Inventory.accessible_objects(self.request.user, 'read_role')
qs = qs.select_related('admin_role', 'read_role', 'update_role', 'use_role', 'adhoc_role') qs = qs.select_related('admin_role', 'read_role', 'update_role', 'use_role', 'adhoc_role')
qs = qs.prefetch_related('created_by', 'modified_by', 'organization')
return qs return qs

View File

@ -1809,6 +1809,9 @@ class UnifiedJobTemplateAccess(BaseAccess):
'created_by', 'created_by',
'modified_by', 'modified_by',
'next_schedule', 'next_schedule',
)
# prefetch last/current jobs so we get the real instance
qs = qs.prefetch_related(
'last_job', 'last_job',
'current_job', 'current_job',
) )