Skip to content

Commit

Permalink
[Improvement-15448] Remove redundant query in project list (#16341)
Browse files Browse the repository at this point in the history
* remove redundant query
  • Loading branch information
SbloodyS committed Jul 19, 2024
1 parent ebaa819 commit c5e5ff7
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -393,6 +394,19 @@ public Result queryProjectListPaging(User loginUser, Integer pageSize, Integer p
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.setTotalList(projectList);
result.setData(pageInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ private Project getProject() {
project.setName("PJ-001");
project.setPerm(7);
project.setDefCount(0);
project.setInstRunningCount(0);
return project;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,4 @@ public class Project {
@TableField(exist = false)
private int defCount;

/**
* process instance running count
*/
@TableField(exist = false)
private int instRunningCount;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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;
Expand Down Expand Up @@ -170,5 +171,8 @@ List<WorkflowDefinitionCountDto> countDefinitionByProjectCodesV2(@Param("project
* @return project ids list
*/
List<Integer> listProjectIds();

List<Long> queryDefinitionCodeListByProjectCodes(@Param("projectCodes") List<Long> projectCodes);

List<ProjectProcessDefinitionCount> queryProjectProcessDefinitionCountByProjectCodes(@Param("projectCodes") List<Long> projectCodes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,16 @@
#{i}
</foreach>
</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>
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,10 @@
</select>
<select id="queryProjectListPaging" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select
<include refid="baseSqlV2">
<property name="alias" value="p"/>
</include> ,
u.user_name as user_name,
count(distinct def.id) AS def_count,
count(distinct inst.id) as inst_running_count
<include refid="baseSqlV2">
<property name="alias" value="p"/>
</include>
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
<if test="projectsIds != null and projectsIds.size() > 0">
and p.id in
Expand All @@ -108,7 +98,7 @@
OR p.description LIKE concat('%', #{searchName}, '%')
)
</if>
group by p.id,u.user_name
group by p.id
order by p.id desc
</select>
<select id="queryAuthedProjectListByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,18 @@ public FileManagePage(RemoteWebDriver driver) {
}

public FileManagePage createDirectory(String name) {
waitForPageLoading();
buttonCreateDirectory().click();

createDirectoryBox().inputDirectoryName().sendKeys(name);
WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(createDirectoryBox().buttonSubmit()));
createDirectoryBox().buttonSubmit().click();

return this;
}

public FileManagePage cancelCreateDirectory(String name) {
waitForPageLoading();
buttonCreateDirectory().click();

createDirectoryBox().inputDirectoryName().sendKeys(name);
Expand All @@ -109,6 +112,7 @@ public FileManagePage cancelCreateDirectory(String name) {
}

public FileManagePage rename(String currentName, String AfterName) {
waitForPageLoading();
fileList()
.stream()
.filter(it -> it.getText().contains(currentName))
Expand Down Expand Up @@ -138,12 +142,15 @@ public FileManagePage createSubDirectory(String directoryName, String subDirecto
buttonCreateDirectory().click();

createDirectoryBox().inputDirectoryName().sendKeys(subDirectoryName);
WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(createDirectoryBox().buttonSubmit()));
createDirectoryBox().buttonSubmit().click();

return this;
}

public FileManagePage delete(String name) {
waitForPageLoading();
fileList()
.stream()
.filter(it -> it.getText().contains(name))
Expand All @@ -160,7 +167,7 @@ public FileManagePage delete(String name) {

// todo: add file type
public FileManagePage createFile(String fileName, String scripts) {

waitForPageLoading();
WebDriverWaitFactory.createWebDriverWait(driver)
.until(ExpectedConditions.elementToBeClickable(buttonCreateFile()));

Expand Down Expand Up @@ -189,6 +196,7 @@ public FileManagePage createFileUntilSuccess(String fileName, String scripts) {
}

public FileManagePage editFile(String fileName, String scripts) {
waitForPageLoading();
fileList()
.stream()
.filter(it -> it.getText().contains(fileName))
Expand All @@ -210,6 +218,7 @@ public FileManagePage editFile(String fileName, String scripts) {
}

public FileManagePage uploadFile(String filePath) {
waitForPageLoading();
buttonUploadFile().click();

driver.setFileDetector(new LocalFileDetector());
Expand All @@ -221,6 +230,7 @@ public FileManagePage uploadFile(String filePath) {
}

public FileManagePage downloadFile(String fileName) {
waitForPageLoading();
fileList()
.stream()
.filter(it -> it.getText().contains(fileName))
Expand All @@ -233,6 +243,10 @@ public FileManagePage downloadFile(String fileName) {
return this;
}

private void waitForPageLoading() {
WebDriverWaitFactory.createWebDriverWait(driver).until(ExpectedConditions.urlContains("/resource/file-manage"));
}

@Getter
public class CreateDirectoryBox {

Expand Down
1 change: 0 additions & 1 deletion dolphinscheduler-ui/src/locales/en_US/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default {
project_description: 'Project Description',
owned_users: 'Owned Users',
workflow_define_count: 'Workflow Define Count',
process_instance_running_count: 'Process Instance Running Count',
description: 'Description',
create_time: 'Create Time',
update_time: 'Update Time',
Expand Down
1 change: 0 additions & 1 deletion dolphinscheduler-ui/src/locales/zh_CN/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default {
project_description: '项目描述',
owned_users: '所属用户',
workflow_define_count: '工作流定义数',
process_instance_running_count: '正在运行的流程数',
description: '描述',
create_time: '创建时间',
update_time: '更新时间',
Expand Down
8 changes: 0 additions & 8 deletions dolphinscheduler-ui/src/views/projects/list/use-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ export function useTable() {
tooltip: true
}
},
{
title: t('project.list.process_instance_running_count'),
key: 'instRunningCount',
width: 120,
ellipsis: {
tooltip: true
}
},
{
title: t('project.list.description'),
key: 'description',
Expand Down

0 comments on commit c5e5ff7

Please sign in to comment.