diff --git a/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java index 81dc5b3d..c0a55ac8 100644 --- a/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java +++ b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import javax.inject.Inject; @@ -180,26 +181,31 @@ public class LacertaVcsImpl implements LacertaVcs { }); } - private ArrayList getRevBeforeTargetId(String revId){ - ArrayList vcsRevEntities = new ArrayList<>(database.vcsRevDao().findByDocumentId(this.documentId)); - ArrayList vcsRevEntitiesBeforeTarget = new ArrayList<>(); - vcsRevEntities.forEach(vcsRevEntity -> { - if(vcsRevEntity.id.equals(revId)){ + private CompletableFuture> getRevBeforeTargetIdAsync(String revId){ + return CompletableFuture.supplyAsync(() -> { + ArrayList vcsRevEntities = new ArrayList<>(database.vcsRevDao().findByDocumentId(this.documentId)); + ArrayList vcsRevEntitiesBeforeTarget = new ArrayList<>(); + vcsRevEntities.forEach(vcsRevEntity -> { + if(vcsRevEntity.id.equals(revId)){ + vcsRevEntitiesBeforeTarget.add(vcsRevEntity); + return; + } vcsRevEntitiesBeforeTarget.add(vcsRevEntity); - return; - } - vcsRevEntitiesBeforeTarget.add(vcsRevEntity); - }); + }); - return vcsRevEntitiesBeforeTarget; + return vcsRevEntitiesBeforeTarget; + }); } - private ArrayList getLogInRevs(ArrayList vcsRevEntities){ - List logIds = new ArrayList<>(); - vcsRevEntities.forEach(vcsRevEntity -> { - logIds.addAll(vcsRevEntity.logIds); + private CompletableFuture> getLogInRevs(ArrayList vcsRevEntities){ + return CompletableFuture.supplyAsync(() -> { + List logIds = new ArrayList<>(); + vcsRevEntities.forEach(vcsRevEntity -> { + logIds.addAll(vcsRevEntity.logIds); + }); + // TODO-rca: ソートしないといけないかも(順番が保証されているわけではない + 順番が変わるとほぼ確実に壊れる) + return new ArrayList<>(database.vcsLogDao().findByIds(logIds)); }); - return new ArrayList<>(database.vcsLogDao().findByIds(logIds)); } private ArrayList getLogInRev(VcsRevEntity revEntity) { @@ -209,8 +215,8 @@ public class LacertaVcsImpl implements LacertaVcs { @Override public CompletableFuture> getDocumentPagePathListRev(String revId) { return CompletableFuture.supplyAsync(() -> { - ArrayList vcsRevEntities = getRevBeforeTargetId(revId); - ArrayList vcsLogEntities = getLogInRevs(vcsRevEntities); + ArrayList vcsRevEntities = getRevBeforeTargetIdAsync(revId).join(); + ArrayList vcsLogEntities = getLogInRevs(vcsRevEntities).join(); // finalで宣言しないとLambda式内で扱えないので final ArrayList[] fileNameList = new ArrayList[]{new ArrayList<>()};