diff options
| author | shizhendong <[email protected]> | 2024-11-07 15:05:16 +0800 |
|---|---|---|
| committer | shizhendong <[email protected]> | 2024-11-07 15:05:16 +0800 |
| commit | 336c4ed778751ebcadcfa01b550463ef3fe79026 (patch) | |
| tree | bdb35d198501a9c80d034f02b3f5348aa16e6050 | |
| parent | e29ffc62d9213c1085d4bc75402071b0491670ba (diff) | |
fix: application 详情接口查询 app lastCommit 效率优化测试
| -rw-r--r-- | src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java index bf0e5b7..c3bd2fe 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java @@ -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); } |
