Browse Source

[Improvement-15448] Remove redundant query in project list (#16341)

* remove redundant query
dev
xiangzihao 4 months ago committed by GitHub
parent
commit
c5e5ff7b19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java
  2. 1
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
  3. 5
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java
  4. 32
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProjectProcessDefinitionCount.java
  5. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  6. 12
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  7. 14
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml
  8. 18
      dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/resource/FileManagePage.java
  9. 1
      dolphinscheduler-ui/src/locales/en_US/project.ts
  10. 1
      dolphinscheduler-ui/src/locales/zh_CN/project.ts
  11. 8
      dolphinscheduler-ui/src/views/projects/list/use-table.ts

14
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.common.utils.CodeGenerateUtils.CodeGenerateException;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Project; 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.ProjectUser;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
@ -393,6 +394,19 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectServic
project.setPerm(Constants.DEFAULT_ADMIN_PERMISSION); project.setPerm(Constants.DEFAULT_ADMIN_PERMISSION);
} }
} }
List<User> userList = userMapper.selectByIds(projectList.stream()
.map(Project::getUserId).distinct().collect(Collectors.toList()));
List<ProjectProcessDefinitionCount> 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.setTotal((int) projectIPage.getTotal());
pageInfo.setTotalList(projectList); pageInfo.setTotalList(projectList);
result.setData(pageInfo); result.setData(pageInfo);

1
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java

@ -833,7 +833,6 @@ public class UsersServiceTest {
project.setName("PJ-001"); project.setName("PJ-001");
project.setPerm(7); project.setPerm(7);
project.setDefCount(0); project.setDefCount(0);
project.setInstRunningCount(0);
return project; return project;
} }

5
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java

@ -91,9 +91,4 @@ public class Project {
@TableField(exist = false) @TableField(exist = false)
private int defCount; private int defCount;
/**
* process instance running count
*/
@TableField(exist = false)
private int instRunningCount;
} }

32
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;
}

4
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.DependentSimplifyDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProjectProcessDefinitionCount;
import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -170,5 +171,8 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
* @return project ids list * @return project ids list
*/ */
List<Integer> listProjectIds(); List<Integer> listProjectIds();
List<Long> queryDefinitionCodeListByProjectCodes(@Param("projectCodes") List<Long> projectCodes); List<Long> queryDefinitionCodeListByProjectCodes(@Param("projectCodes") List<Long> projectCodes);
List<ProjectProcessDefinitionCount> queryProjectProcessDefinitionCountByProjectCodes(@Param("projectCodes") List<Long> projectCodes);
} }

12
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml

@ -194,4 +194,16 @@
#{i} #{i}
</foreach> </foreach>
</select> </select>
<select id="queryProjectProcessDefinitionCountByProjectCodes" resultType="org.apache.dolphinscheduler.dao.entity.ProjectProcessDefinitionCount">
select
project_code as projectCode
,count(*) as count
from t_ds_process_definition
where project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
group by project_code
</select>
</mapper> </mapper>

14
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

@ -84,18 +84,8 @@
select select
<include refid="baseSqlV2"> <include refid="baseSqlV2">
<property name="alias" value="p"/> <property name="alias" value="p"/>
</include> , </include>
u.user_name as user_name,
count(distinct def.id) AS def_count,
count(distinct inst.id) as inst_running_count
from t_ds_project p from t_ds_project p
left join t_ds_user u on u.id=p.user_id
left join t_ds_process_definition def
on def.project_code = p.code
left join t_ds_process_instance inst
on inst.process_definition_code = def.code
and inst.process_definition_version = def.version
and inst.state = 1
where 1=1 where 1=1
<if test="projectsIds != null and projectsIds.size() > 0"> <if test="projectsIds != null and projectsIds.size() > 0">
and p.id in and p.id in
@ -108,7 +98,7 @@
OR p.description LIKE concat('%', #{searchName}, '%') OR p.description LIKE concat('%', #{searchName}, '%')
) )
</if> </if>
group by p.id,u.user_name group by p.id
order by p.id desc order by p.id desc
</select> </select>
<select id="queryAuthedProjectListByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project"> <select id="queryAuthedProjectListByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">

18
dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/resource/FileManagePage.java

@ -91,15 +91,18 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
} }
public FileManagePage createDirectory(String name) { public FileManagePage createDirectory(String name) {
waitForPageLoading();
buttonCreateDirectory().click(); buttonCreateDirectory().click();
createDirectoryBox().inputDirectoryName().sendKeys(name); createDirectoryBox().inputDirectoryName().sendKeys(name);
WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(createDirectoryBox().buttonSubmit()));
createDirectoryBox().buttonSubmit().click(); createDirectoryBox().buttonSubmit().click();
return this; return this;
} }
public FileManagePage cancelCreateDirectory(String name) { public FileManagePage cancelCreateDirectory(String name) {
waitForPageLoading();
buttonCreateDirectory().click(); buttonCreateDirectory().click();
createDirectoryBox().inputDirectoryName().sendKeys(name); createDirectoryBox().inputDirectoryName().sendKeys(name);
@ -109,6 +112,7 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
} }
public FileManagePage rename(String currentName, String AfterName) { public FileManagePage rename(String currentName, String AfterName) {
waitForPageLoading();
fileList() fileList()
.stream() .stream()
.filter(it -> it.getText().contains(currentName)) .filter(it -> it.getText().contains(currentName))
@ -138,12 +142,15 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
buttonCreateDirectory().click(); buttonCreateDirectory().click();
createDirectoryBox().inputDirectoryName().sendKeys(subDirectoryName); createDirectoryBox().inputDirectoryName().sendKeys(subDirectoryName);
WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(createDirectoryBox().buttonSubmit()));
createDirectoryBox().buttonSubmit().click(); createDirectoryBox().buttonSubmit().click();
return this; return this;
} }
public FileManagePage delete(String name) { public FileManagePage delete(String name) {
waitForPageLoading();
fileList() fileList()
.stream() .stream()
.filter(it -> it.getText().contains(name)) .filter(it -> it.getText().contains(name))
@ -160,7 +167,7 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
// todo: add file type // todo: add file type
public FileManagePage createFile(String fileName, String scripts) { public FileManagePage createFile(String fileName, String scripts) {
waitForPageLoading();
WebDriverWaitFactory.createWebDriverWait(driver) WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(buttonCreateFile())); .until(ExpectedConditions.elementToBeClickable(buttonCreateFile()));
@ -189,6 +196,7 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
} }
public FileManagePage editFile(String fileName, String scripts) { public FileManagePage editFile(String fileName, String scripts) {
waitForPageLoading();
fileList() fileList()
.stream() .stream()
.filter(it -> it.getText().contains(fileName)) .filter(it -> it.getText().contains(fileName))
@ -210,6 +218,7 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
} }
public FileManagePage uploadFile(String filePath) { public FileManagePage uploadFile(String filePath) {
waitForPageLoading();
buttonUploadFile().click(); buttonUploadFile().click();
driver.setFileDetector(new LocalFileDetector()); driver.setFileDetector(new LocalFileDetector());
@ -221,6 +230,7 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
} }
public FileManagePage downloadFile(String fileName) { public FileManagePage downloadFile(String fileName) {
waitForPageLoading();
fileList() fileList()
.stream() .stream()
.filter(it -> it.getText().contains(fileName)) .filter(it -> it.getText().contains(fileName))
@ -233,6 +243,10 @@ public class FileManagePage extends NavBarPage implements ResourcePage.Tab {
return this; return this;
} }
private void waitForPageLoading() {
WebDriverWaitFactory.createWebDriverWait(driver).until(ExpectedConditions.urlContains("/resource/file-manage"));
}
@Getter @Getter
public class CreateDirectoryBox { public class CreateDirectoryBox {

1
dolphinscheduler-ui/src/locales/en_US/project.ts

@ -27,7 +27,6 @@ export default {
project_description: 'Project Description', project_description: 'Project Description',
owned_users: 'Owned Users', owned_users: 'Owned Users',
workflow_define_count: 'Workflow Define Count', workflow_define_count: 'Workflow Define Count',
process_instance_running_count: 'Process Instance Running Count',
description: 'Description', description: 'Description',
create_time: 'Create Time', create_time: 'Create Time',
update_time: 'Update Time', update_time: 'Update Time',

1
dolphinscheduler-ui/src/locales/zh_CN/project.ts

@ -27,7 +27,6 @@ export default {
project_description: '项目描述', project_description: '项目描述',
owned_users: '所属用户', owned_users: '所属用户',
workflow_define_count: '工作流定义数', workflow_define_count: '工作流定义数',
process_instance_running_count: '正在运行的流程数',
description: '描述', description: '描述',
create_time: '创建时间', create_time: '创建时间',
update_time: '更新时间', update_time: '更新时间',

8
dolphinscheduler-ui/src/views/projects/list/use-table.ts

@ -122,14 +122,6 @@ export function useTable() {
tooltip: true tooltip: true
} }
}, },
{
title: t('project.list.process_instance_running_count'),
key: 'instRunningCount',
width: 120,
ellipsis: {
tooltip: true
}
},
{ {
title: t('project.list.description'), title: t('project.list.description'),
key: 'description', key: 'description',

Loading…
Cancel
Save