ruanwenjun commented on code in PR #16681:
URL: 
https://github.com/apache/dolphinscheduler/pull/16681#discussion_r1796843374


##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkflowDefinitionMapper.xml:
##########
@@ -189,21 +189,39 @@
         select
         code
         from t_ds_workflow_definition
-        where project_code in
-            <foreach collection="projectCodes" index="index" item="i" open="(" 
separator="," close=")">
-                #{i}
-            </foreach>
+        <where>

Review Comment:
   Please revert this change, this kind of check should in `dao`, we need to 
avoid using complex logic in mapper.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java:
##########
@@ -394,12 +394,15 @@ public Result queryProjectListPaging(User loginUser, 
Integer pageSize, Integer p
         List<User> userList = userMapper.selectByIds(projectList.stream()
                 
.map(Project::getUserId).distinct().collect(Collectors.toList()));
         Map<Integer, String> userMap = 
userList.stream().collect(Collectors.toMap(User::getId, User::getUserName));
-        List<ProjectWorkflowDefinitionCount> 
projectWorkflowDefinitionCountList =
-                
workflowDefinitionMapper.queryProjectWorkflowDefinitionCountByProjectCodes(
-                        
projectList.stream().map(Project::getCode).distinct().collect(Collectors.toList()));
-        Map<Long, Integer> projectWorkflowDefinitionCountMap = 
projectWorkflowDefinitionCountList.stream()
-                
.collect(Collectors.toMap(ProjectWorkflowDefinitionCount::getProjectCode,
-                        ProjectWorkflowDefinitionCount::getCount));
+        List<Long> projectCodes = 
projectList.stream().map(Project::getCode).distinct().collect(Collectors.toList());
+        Map<Long, Integer> projectWorkflowDefinitionCountMap = 
Collections.emptyMap();
+        if (CollectionUtils.isNotEmpty(projectCodes)) {
+            projectWorkflowDefinitionCountMap = workflowDefinitionMapper
+                    
.queryProjectWorkflowDefinitionCountByProjectCodes(projectCodes)
+                    .stream()
+                    
.collect(Collectors.toMap(ProjectWorkflowDefinitionCount::getProjectCode,
+                            ProjectWorkflowDefinitionCount::getCount));
+        }

Review Comment:
   If the `projectList` is empty, then we can return early at line 389, then 
the logic would be clearer?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to