This is an automated email from the ASF dual-hosted git repository.
jinyleechina pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new bc99575 [DS-7256][refactor] Optimization for task instances query
(#7331)
bc99575 is described below
commit bc995752d6b52f2f94bf17ea806c60f8d63b7342
Author: mgduoduo <[email protected]>
AuthorDate: Wed Dec 15 10:53:52 2021 +0800
[DS-7256][refactor] Optimization for task instances query (#7331)
- assemble a Map<Long, User> outside of the loop instead of the query inside
Co-authored-by: gq47193 <[email protected]>
---
.../api/service/impl/TaskInstanceServiceImpl.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
index 64ba304..ab53c58 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskInstanceServiceImpl.java
@@ -42,6 +42,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -137,12 +138,13 @@ public class TaskInstanceServiceImpl extends
BaseServiceImpl implements TaskInst
exclusionSet.add(Constants.CLASS);
exclusionSet.add("taskJson");
List<TaskInstance> taskInstanceList = taskInstanceIPage.getRecords();
-
+ List<Integer> executorIds =
taskInstanceList.stream().map(TaskInstance::getExecutorId).distinct().collect(Collectors.toList());
+ List<User> users = usersService.queryUser(executorIds);
+ Map<Integer, User> userMap =
users.stream().collect(Collectors.toMap(User::getId, v -> v));
for (TaskInstance taskInstance : taskInstanceList) {
taskInstance.setDuration(DateUtils.format2Duration(taskInstance.getStartTime(),
taskInstance.getEndTime()));
- User executor =
usersService.queryUser(taskInstance.getExecutorId());
- if (null != executor) {
- taskInstance.setExecutorName(executor.getUserName());
+ if (userMap.containsKey(taskInstance.getExecutorId())) {
+
taskInstance.setExecutorName(userMap.get(taskInstance.getExecutorId()).getUserName());
}
}
pageInfo.setTotal((int) taskInstanceIPage.getTotal());