From 672711d624e62bba96cea339f70ca4b747d824c9 Mon Sep 17 00:00:00 2001 From: hanshuaikang <1758504262@qq.com> Date: Fri, 15 Dec 2023 16:22:38 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E5=87=8F=E5=B0=91=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E5=A4=84=E7=90=86=E6=9D=A1=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E9=A2=9D=E5=A4=96=E6=9F=A5=E8=AF=A2/=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E6=9F=A5=E8=AF=A2=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/core/apis/drf/viewsets/taskflow.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/gcloud/core/apis/drf/viewsets/taskflow.py b/gcloud/core/apis/drf/viewsets/taskflow.py index 9c421418f3..bc60650c91 100644 --- a/gcloud/core/apis/drf/viewsets/taskflow.py +++ b/gcloud/core/apis/drf/viewsets/taskflow.py @@ -204,16 +204,9 @@ def _filter_pending_process(self): :return: """ # 找到所有正在执行中的流程 - # selected_related 只能在 objects 最前面加,此处先查处 ID 列表 - taskflow_instance_ids: typing.List[int] = list( - self.queryset.exclude( - pipeline_instance_id__in=self._fetch_pipeline_instance_ids(statuses=[states.FAILED]) - ).values_list("id", flat=True) - ) - # selected_related 提前查取刚需的关联数据,避免 n+1 查询 - taskflow_instances: typing.List[TaskFlowInstance] = TaskFlowInstance.objects.select_related( - "pipeline_instance" - ).filter(id__in=taskflow_instance_ids) + taskflow_instances = self.queryset.exclude( + pipeline_instance_id__in=self._fetch_pipeline_instance_ids(statuses=[states.FAILED]) + ).select_related("pipeline_instance") # 并行找到全部的等待执行任务 pending_process_taskflow_ids: typing.List[int] = self._fetch_pending_process_taskflow_ids(taskflow_instances) return self.queryset.filter(id__in=pending_process_taskflow_ids)