You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/10/22 15:02:14 UTC

[GitHub] [dolphinscheduler] BongBongBang commented on a diff in pull request #12499: [Improvement][BatchQuery] Batch query ProcessDefinitions belongs to need failover ProcessInstance.

BongBongBang commented on code in PR #12499:
URL: https://github.com/apache/dolphinscheduler/pull/12499#discussion_r1002502591


##########
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java:
##########
@@ -462,6 +462,40 @@ public ProcessDefinition findProcessDefinition(Long processDefinitionCode, int v
         return processDefinition;
     }
 
+    /**
+     * find a batch of process definitions by a map of <code, version>.
+     * @param codeVersionMap Map<code, version>
+     * @return
+     */
+    @Override
+    public List<ProcessDefinition> findProcessDefinitions(Map<Long, Integer> codeVersionMap) {
+        Set<Long> codes = codeVersionMap.keySet();
+        List<ProcessDefinition> processDefinitions = processDefineMapper.queryByCodes(codes);
+        Map<Long, Integer> codeVersionNeedToRetrieve = new HashMap<>();
+        codeVersionNeedToRetrieve.putAll(codeVersionMap);
+        // filter out the code/version entry that don't need to retrieve
+        processDefinitions.forEach(processDefinition -> {
+            long code = processDefinition.getCode();
+            if (codeVersionNeedToRetrieve.containsKey(code) && processDefinition.getVersion() == codeVersionNeedToRetrieve.get(code).intValue()) {
+                codeVersionNeedToRetrieve.remove(code);
+            }
+        });
+        if (!codeVersionNeedToRetrieve.isEmpty()) {
+            List<ProcessDefinition> complementProcessDefinitions = codeVersionNeedToRetrieve.entrySet()
+                    .stream()
+                    .map(entry -> {
+                        ProcessDefinition processDefinition = processDefineLogMapper.queryByDefinitionCodeAndVersion(entry.getKey(), entry.getValue());
+                        if (processDefinition != null) {
+                            processDefinition.setId(0);
+                        }
+                        return processDefinition;
+                    })
+                    .collect(Collectors.toList());
+            processDefinitions.addAll(complementProcessDefinitions);
+        }
+        return processDefinitions;

Review Comment:
   Yeah, got it. It's a better idea. 



-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org