fix: application 列表接口查询 app lastCommit 效率优化测试
This commit is contained in:
@@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -223,6 +224,8 @@ public class GitServiceImpl implements IGitService {
|
||||
treeWalk.setRecursive(true);
|
||||
|
||||
Map<String, String> appIconDataMapping = T.MapUtil.newHashMap();
|
||||
|
||||
List<CompletableFuture<Map>> futureList = T.ListUtil.list(false);
|
||||
while (treeWalk.next()) {
|
||||
String fileName = treeWalk.getNameString();
|
||||
if (T.StrUtil.equals("basic.json", fileName)) {
|
||||
@@ -242,13 +245,27 @@ public class GitServiceImpl implements IGitService {
|
||||
Map<Object, Object> m = T.MapUtil.newHashMap(true);
|
||||
m.putAll(basicJsonMap);
|
||||
|
||||
Iterable<RevCommit> iterable = git.log()
|
||||
.add(branchRef)
|
||||
.addPath(treeWalk.getPathString().replaceAll(fileName, ""))
|
||||
.call();
|
||||
Iterator<RevCommit> iterator = iterable.iterator();
|
||||
RevCommit commit = iterator.hasNext() ? iterator.next() : null;
|
||||
m.put("commit", this.buildAswCommitInfo(commit));
|
||||
String appId = T.MapUtil.getStr(basicJsonMap, "id", "");
|
||||
String appDirPath = treeWalk.getPathString().replaceAll(fileName, "");
|
||||
futureList.add(
|
||||
CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
Iterable<RevCommit> iterable = git.log()
|
||||
.add(branchRef)
|
||||
.addPath(appDirPath)
|
||||
.call();
|
||||
Iterator<RevCommit> iterator = iterable.iterator();
|
||||
RevCommit commit = iterator.hasNext() ? iterator.next() : null;
|
||||
return T.MapUtil.builder()
|
||||
.put("id", appId)
|
||||
.put("commit", this.buildAswCommitInfo(commit))
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.warn(e);
|
||||
}
|
||||
return T.MapUtil.newHashMap();
|
||||
})
|
||||
);
|
||||
|
||||
resultList.add(m);
|
||||
} else if (T.StrUtil.equals("icon.png", fileName)) {
|
||||
@@ -270,8 +287,22 @@ public class GitServiceImpl implements IGitService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).get();
|
||||
futureList.forEach(f -> {
|
||||
Map map = f.getNow(null);
|
||||
if (T.MapUtil.isNotEmpty(map)) {
|
||||
String id = T.MapUtil.getStr(map, "id");
|
||||
Map<Object, Object> item = resultList.stream().filter(m -> T.MapUtil.getStr(m, "id").equals(id)).findFirst().get();
|
||||
item.put("commit", T.MapUtil.get(map, "commit", Map.class));
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.warn(e);
|
||||
}
|
||||
}
|
||||
} catch (IOException | GitAPIException e) {
|
||||
} catch (IOException e) {
|
||||
log.error(e, "[listApplication] [error] [workspaceId: {}] [branch: {}]", workspaceId, branch);
|
||||
throw new ASWException(RCode.ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user