Revert "test"

This reverts commit 74b303f3eb.
This commit is contained in:
ろむねこ 2024-07-05 15:44:22 +09:00
parent 74b303f3eb
commit 72b6473aac
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168

View File

@ -41,31 +41,24 @@ public class ChildDataImpl implements ChildData {
@Override
public CompletableFuture<List<ChildModel>> getChildList(ChildModelCallback callback) { // TODO: リファクタリング
return CompletableFuture.supplyAsync(() -> {
logger.debug("子供リスト取得開始");
return cacheWrapper.getChildList().thenComposeAsync(childList -> {
AtomicReference<List<ChildModel>> childListTmp = new AtomicReference<>();
Thread thread = new Thread(() -> ksActions.syncChildList().thenAccept(childList -> {
if (childListTmp.get() == null || childListTmp.get().isEmpty()) {
logger.debug("子供リスト取得完了: キャッシュよりはやく取得完了 or キャッシュ無し");
if (childList == null || childList.isEmpty()) {
logger.debug("キャッシュ無: 子供リストを取得中...");
return ksActions.syncChildList().thenApply(childListFromServer -> {
if (childListFromServer == null || childListFromServer.isEmpty()) {
callback.onUnchanged();
} else {
callback.onUpdated(childListFromServer);
callback.onUpdated(childList);
}
return childListFromServer;
}).exceptionally(e -> {
logger.error("子供リスト取得失敗: " + e.getMessage());
callback.onFailed(e.getMessage());
return null;
});
} else {
logger.debug("キャッシュ有 (子供数: " + childList.size() + ")");
ksActions.syncChildList().thenAccept(childListFromServer -> {
if (childListFromServer != null) {
boolean isChanged = childListFromServer.size() != childList.size() ||
childListFromServer.stream().anyMatch(child -> childList.stream().noneMatch(childTmp -> child.getId().equals(childTmp.getId())));
boolean isChanged =
childList.size() != childListTmp.get().size() ||
childList.stream().anyMatch(child -> childListTmp.get().stream().noneMatch(childTmp -> child.getId().equals(childTmp.getId())));
if (isChanged) {
logger.debug("子供リスト取得完了: キャッシュと比較して変更あり");
callback.onUpdated(childListFromServer);
callback.onUpdated(childList);
} else {
logger.debug("子供リスト取得完了: キャッシュと比較して変更なし");
callback.onUnchanged();
@ -75,13 +68,26 @@ public class ChildDataImpl implements ChildData {
logger.error("子供リスト取得失敗: " + e.getMessage());
callback.onFailed(e.getMessage());
return null;
});
return CompletableFuture.completedFuture(childList);
}));
thread.start();
return cacheWrapper.getChildList().thenApply(childList -> {
if (childList == null || childList.isEmpty()) {
try {
logger.debug("キャッシュ無: 子供リスト取得スレッド待機");
thread.join();
return cacheWrapper.getChildList().join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else {
logger.debug("キャッシュ有 (子供数: " + childList.size() + ")");
childListTmp.set(childList);
return childList;
}
}).join();
});
}
@Override
public void updateChild(ChildModel child) {