Integrate unnecessary queries for better performance.

This commit is contained in:
Aaron Tan
2016-10-28 15:03:17 -04:00
parent 6ecd45681a
commit 62e0291f86

View File

@@ -1090,8 +1090,7 @@ class ProjectUpdateDetail(RetrieveDestroyAPIView):
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
obj = self.get_object() obj = self.get_object()
for unified_job_node in obj.unified_job_nodes.all(): if obj.unified_job_nodes.filter(workflow_job__status__in=ACTIVE_STATES).exists():
if unified_job_node.workflow_job.status in ACTIVE_STATES:
raise PermissionDenied(detail='Can not delete job resource when associated workflow job is running.') raise PermissionDenied(detail='Can not delete job resource when associated workflow job is running.')
return super(ProjectUpdateDetail, self).destroy(request, *args, **kwargs) return super(ProjectUpdateDetail, self).destroy(request, *args, **kwargs)
@@ -2176,8 +2175,7 @@ class InventoryUpdateDetail(RetrieveDestroyAPIView):
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
obj = self.get_object() obj = self.get_object()
for unified_job_node in obj.unified_job_nodes.all(): if obj.unified_job_nodes.filter(workflow_job__status__in=ACTIVE_STATES).exists():
if unified_job_node.workflow_job.status in ACTIVE_STATES:
raise PermissionDenied(detail='Can not delete job resource when associated workflow job is running.') raise PermissionDenied(detail='Can not delete job resource when associated workflow job is running.')
return super(InventoryUpdateDetail, self).destroy(request, *args, **kwargs) return super(InventoryUpdateDetail, self).destroy(request, *args, **kwargs)
@@ -2886,8 +2884,7 @@ class JobDetail(RetrieveUpdateDestroyAPIView):
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
obj = self.get_object() obj = self.get_object()
for unified_job_node in obj.unified_job_nodes.all(): if obj.unified_job_nodes.filter(workflow_job__status__in=ACTIVE_STATES).exists():
if unified_job_node.workflow_job.status in ACTIVE_STATES:
raise PermissionDenied(detail='Can not delete job resource when associated workflow job is running.') raise PermissionDenied(detail='Can not delete job resource when associated workflow job is running.')
return super(JobDetail, self).destroy(request, *args, **kwargs) return super(JobDetail, self).destroy(request, *args, **kwargs)