一部を非同期にした

This commit is contained in:
r-ca 2024-01-24 17:55:23 +09:00
parent cd1a58dcc0
commit 8c4e651a79
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

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