From c5e5ff7b1960083057cee324c2f69020d24bb703 Mon Sep 17 00:00:00 2001 From: xiangzihao <460888207@qq.com> Date: Fri, 19 Jul 2024 10:16:47 +0800 Subject: [PATCH] [Improvement-15448] Remove redundant query in project list (#16341) * remove redundant query --- .../api/service/impl/ProjectServiceImpl.java | 14 ++++++++ .../api/service/UsersServiceTest.java | 1 - .../dolphinscheduler/dao/entity/Project.java | 5 --- .../entity/ProjectProcessDefinitionCount.java | 32 +++++++++++++++++++ .../dao/mapper/ProcessDefinitionMapper.java | 4 +++ .../dao/mapper/ProcessDefinitionMapper.xml | 12 +++++++ .../dao/mapper/ProjectMapper.xml | 18 +++-------- .../e2e/pages/resource/FileManagePage.java | 18 +++++++++-- .../src/locales/en_US/project.ts | 1 - .../src/locales/zh_CN/project.ts | 1 - .../src/views/projects/list/use-table.ts | 8 ----- 11 files changed, 82 insertions(+), 32 deletions(-) create mode 100644 dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectProcessDefinitionCount.java diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index b5c329c4fd..3c623b7029 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.ProjectProcessDefinitionCount; import org.apache.dolphinscheduler.dao.entity.ProjectUser; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; @@ -393,6 +394,19 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic project.setPerm(Constants.DEFAULT_ADMIN_PERMISSION); } } + List userList = userMapper.selectByIds(projectList.stream() + .map(Project::getUserId).distinct().collect(Collectors.toList())); + List projectProcessDefinitionCountList = + processDefinitionMapper.queryProjectProcessDefinitionCountByProjectCodes( + projectList.stream().map(Project::getCode).distinct().collect(Collectors.toList())); + for (Project project : projectList) { + project.setUserName(userList.stream().filter(user -> user.getId().equals(project.getUserId())) + .findFirst().map(User::getUserName).orElse(null)); + project.setDefCount(projectProcessDefinitionCountList.stream() + .filter(projectProcessDefinitionCount -> projectProcessDefinitionCount.getProjectCode() + .equals(project.getCode())) + .findFirst().map(ProjectProcessDefinitionCount::getCount).orElse(0)); + } pageInfo.setTotal((int) projectIPage.getTotal()); pageInfo.setTotalList(projectList); result.setData(pageInfo); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index 290ffefe26..493af5fb2e 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java @@ -833,7 +833,6 @@ public class UsersServiceTest { project.setName("PJ-001"); project.setPerm(7); project.setDefCount(0); - project.setInstRunningCount(0); return project; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java index f3a626f5cd..ccce0b70e7 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java @@ -91,9 +91,4 @@ public class Project { @TableField(exist = false) private int defCount; - /** - * process instance running count - */ - @TableField(exist = false) - private int instRunningCount; } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectProcessDefinitionCount.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectProcessDefinitionCount.java new file mode 100644 index 0000000000..7b796d23d2 --- /dev/null +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectProcessDefinitionCount.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.dolphinscheduler.dao.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProjectProcessDefinitionCount { + + private Long projectCode; + + private Integer count; +} diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java index 689e93414b..22d354b5d2 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java @@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.dao.entity.DependentSimplifyDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; +import org.apache.dolphinscheduler.dao.entity.ProjectProcessDefinitionCount; import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; import org.apache.ibatis.annotations.Param; @@ -170,5 +171,8 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @return project ids list */ List listProjectIds(); + List queryDefinitionCodeListByProjectCodes(@Param("projectCodes") List projectCodes); + + List queryProjectProcessDefinitionCountByProjectCodes(@Param("projectCodes") List projectCodes); } diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml index bcd21647b3..8c4f57f4db 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml @@ -194,4 +194,16 @@ #{i} + + diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml index 296a42a5fb..ddf4c0c490 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml @@ -82,20 +82,10 @@