From 282c09bbd1f2f0c61f02d731c9f2325adb7338cb Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 07:10:41 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E3=81=AB=E9=81=A1=E3=82=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/vcs/impl/LacertaVcsImpl.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 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 de0b3fd2..5a89d6e4 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 @@ -1,6 +1,7 @@ package one.nem.lacerta.vcs.impl; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -195,16 +196,20 @@ public class LacertaVcsImpl implements LacertaVcs { } private CompletableFuture> getRevBeforeTargetIdAsync(String revId){ + logger.debug(TAG, "getRevBeforeTargetIdAsync called: " + revId); return CompletableFuture.supplyAsync(() -> { ArrayList vcsRevEntities = new ArrayList<>(database.vcsRevDao().findByDocumentId(this.documentId)); + // 古い順に並び替え + vcsRevEntities.sort(Comparator.comparing(a -> a.createdAt)); ArrayList vcsRevEntitiesBeforeTarget = new ArrayList<>(); - vcsRevEntities.forEach(vcsRevEntity -> { + for (VcsRevEntity vcsRevEntity : vcsRevEntities) { if(vcsRevEntity.id.equals(revId)){ + logger.debug(TAG, "getRevBeforeTargetIdAsync: Target found"); vcsRevEntitiesBeforeTarget.add(vcsRevEntity); - return; + break; } vcsRevEntitiesBeforeTarget.add(vcsRevEntity); - }); + } logger.debug(TAG, "getRevBeforeTargetIdAsync finished\nResult size: " + vcsRevEntitiesBeforeTarget.size()); return vcsRevEntitiesBeforeTarget; }); @@ -216,8 +221,8 @@ public class LacertaVcsImpl implements LacertaVcs { vcsRevEntities.forEach(vcsRevEntity -> { logIds.addAll(vcsRevEntity.logIds); }); - // TODO-rca: ソートしないといけないかも(順番が保証されているわけではない + 順番が変わるとほぼ確実に壊れる) ArrayList vcsLogEntities = new ArrayList<>(database.vcsLogDao().findByIds(logIds)); + vcsLogEntities.sort(Comparator.comparing(a -> a.createdAt)); logger.debug(TAG, "getLogInRevsAsync finished\nResult size: " + vcsLogEntities.size()); return vcsLogEntities; }); @@ -235,7 +240,13 @@ public class LacertaVcsImpl implements LacertaVcs { public CompletableFuture> getDocumentPagePathListRev(String revId) { return CompletableFuture.supplyAsync(() -> { logger.debug(TAG, "getDocumentPagePathListRev"); - ArrayList vcsLogEntities = getRevBeforeTargetIdAsync(revId).thenCompose(this::getLogInRevsAsync).join(); + ArrayList vcsRevEntities = getRevBeforeTargetIdAsync(revId).join(); + + logger.debug(TAG, "getDocumentPagePathListRev: vcsRevEntities size: " + vcsRevEntities.size()); + + ArrayList vcsLogEntities = getLogInRevsAsync(vcsRevEntities).join(); + + logger.debug(TAG, "getDocumentPagePathListRev: vcsLogEntities size: " + vcsLogEntities.size()); ArrayList fileNameList = new ArrayList<>(); for(VcsLogEntity vcsLogEntity : vcsLogEntities){