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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -223,6 +224,8 @@ public class GitServiceImpl implements IGitService {
|
|||||||
treeWalk.setRecursive(true);
|
treeWalk.setRecursive(true);
|
||||||
|
|
||||||
Map<String, String> appIconDataMapping = T.MapUtil.newHashMap();
|
Map<String, String> appIconDataMapping = T.MapUtil.newHashMap();
|
||||||
|
|
||||||
|
List<CompletableFuture<Map>> futureList = T.ListUtil.list(false);
|
||||||
while (treeWalk.next()) {
|
while (treeWalk.next()) {
|
||||||
String fileName = treeWalk.getNameString();
|
String fileName = treeWalk.getNameString();
|
||||||
if (T.StrUtil.equals("basic.json", fileName)) {
|
if (T.StrUtil.equals("basic.json", fileName)) {
|
||||||
@@ -242,13 +245,27 @@ public class GitServiceImpl implements IGitService {
|
|||||||
Map<Object, Object> m = T.MapUtil.newHashMap(true);
|
Map<Object, Object> m = T.MapUtil.newHashMap(true);
|
||||||
m.putAll(basicJsonMap);
|
m.putAll(basicJsonMap);
|
||||||
|
|
||||||
Iterable<RevCommit> iterable = git.log()
|
String appId = T.MapUtil.getStr(basicJsonMap, "id", "");
|
||||||
.add(branchRef)
|
String appDirPath = treeWalk.getPathString().replaceAll(fileName, "");
|
||||||
.addPath(treeWalk.getPathString().replaceAll(fileName, ""))
|
futureList.add(
|
||||||
.call();
|
CompletableFuture.supplyAsync(() -> {
|
||||||
Iterator<RevCommit> iterator = iterable.iterator();
|
try {
|
||||||
RevCommit commit = iterator.hasNext() ? iterator.next() : null;
|
Iterable<RevCommit> iterable = git.log()
|
||||||
m.put("commit", this.buildAswCommitInfo(commit));
|
.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);
|
resultList.add(m);
|
||||||
} else if (T.StrUtil.equals("icon.png", fileName)) {
|
} 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);
|
log.error(e, "[listApplication] [error] [workspaceId: {}] [branch: {}]", workspaceId, branch);
|
||||||
throw new ASWException(RCode.ERROR);
|
throw new ASWException(RCode.ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user