mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-04 21:28:00 +08:00
[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 <gq47193@ly.com>
This commit is contained in:
parent
6b5c393449
commit
bc995752d6
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user