move various items to prefetch for optimization

This commit is contained in:
AlanCoding 2016-12-11 07:31:04 -05:00
parent 75a85cdab2
commit a90bafe6f0
2 changed files with 5 additions and 0 deletions

View File

@ -1024,6 +1024,7 @@ class ProjectList(ListCreateAPIView):
'update_role',
'read_role',
)
projects_qs = projects_qs.prefetch_related('last_job', 'created_by')
return projects_qs
@ -1579,6 +1580,7 @@ class InventoryList(ListCreateAPIView):
def get_queryset(self):
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.prefetch_related('created_by', 'modified_by', 'organization')
return qs

View File

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