From 8c4e651a7956ec43f913109ec110353d5e66c462 Mon Sep 17 00:00:00 2001 From: r-ca Date: Wed, 24 Jan 2024 17:55:23 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E9=83=A8=E3=82=92=E9=9D=9E=E5=90=8C?= =?UTF-8?q?=E6=9C=9F=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/vcs/impl/LacertaVcsImpl.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) 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<>()};