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 0ba1f59..7153579 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 @@ -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 appIconDataMapping = T.MapUtil.newHashMap(); + + List> 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 m = T.MapUtil.newHashMap(true); m.putAll(basicJsonMap); - Iterable iterable = git.log() - .add(branchRef) - .addPath(treeWalk.getPathString().replaceAll(fileName, "")) - .call(); - Iterator 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 iterable = git.log() + .add(branchRef) + .addPath(appDirPath) + .call(); + Iterator 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 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); }