fix: application 详情接口查询 app lastCommit 效率优化测试
This commit is contained in:
@@ -594,7 +594,7 @@ public class GitServiceImpl implements IGitService {
|
||||
ObjectId branchRef = repository.resolve(branch);
|
||||
result.put("commitId", branchRef.getName());
|
||||
|
||||
List<Object> files = T.ListUtil.list(true);
|
||||
List<Map<Object, Object>> files = T.ListUtil.list(true);
|
||||
try (TreeWalk treeWalk = new TreeWalk(repository);
|
||||
RevWalk revWalk = new RevWalk(repository)) {
|
||||
|
||||
@@ -602,26 +602,29 @@ public class GitServiceImpl implements IGitService {
|
||||
treeWalk.setFilter(PathFilter.create("applications/" + applicationName + "/"));
|
||||
treeWalk.setRecursive(true);
|
||||
|
||||
Map<String, String> appFilePathMapping = T.MapUtil.newHashMap(true);
|
||||
while (treeWalk.next()) {
|
||||
String pathString = treeWalk.getPathString();
|
||||
Map<Object, Object> m = T.MapUtil.builder()
|
||||
.put("path", treeWalk.getPathString())
|
||||
.put("path", pathString)
|
||||
.build();
|
||||
|
||||
Map<Object, Object> fileContent = this.getFileContent(repository, treeWalk.getPathString(), treeWalk.getObjectId(0));
|
||||
Map<Object, Object> fileContent = this.getFileContent(repository, pathString, treeWalk.getObjectId(0));
|
||||
m.putAll(fileContent);
|
||||
|
||||
// lastCommitId
|
||||
Iterable<RevCommit> iterable = git.log()
|
||||
.add(branchRef)
|
||||
.addPath(treeWalk.getPathString())
|
||||
.call();
|
||||
Iterator<RevCommit> iterator = iterable.iterator();
|
||||
m.put("lastCommitId", iterator.hasNext() ? iterator.next().getName() : null);
|
||||
files.add(m);
|
||||
|
||||
appFilePathMapping.put(pathString, pathString);
|
||||
}
|
||||
|
||||
Map<String, RevCommit> lastCommitMapping = this.getLastCommitIdDataByPath(repository, branch, appFilePathMapping);
|
||||
for (Map<Object, Object> m : files) {
|
||||
String path = T.MapUtil.getStr(m, "path");
|
||||
RevCommit revCommit = lastCommitMapping.get(path);
|
||||
m.put("lastCommitId", revCommit != null ? revCommit.getName() : null);
|
||||
}
|
||||
}
|
||||
result.put("files", files);
|
||||
} catch (IOException | GitAPIException e) {
|
||||
} catch (IOException e) {
|
||||
log.error(e, "[infoApplication] [error] [workspaceId: {}] [branch: {}] [application: {}]", workspaceId, branch, applicationName);
|
||||
throw new ASWException(RCode.ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user