From 8e776eac54fd8738f2594dbe970de0d5bc410199 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 20 Feb 2024 11:28:22 +0100 Subject: [PATCH] refactor: Refined stream-definition in `StorageStrategy#write` * Changed the stream-definition to a more natural order. * As a result, the stored `ChatRoomInfo`-instances do not have to be handed clumsily to the following stream. --- .../implementation/StorageStrategy.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java index 94b2bb45..647ac523 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java @@ -17,19 +17,16 @@ public interface StorageStrategy default Mono write(ChatHomeService chatHomeService) { - return writeChatRoomInfo( - chatHomeService - .getChatRoomInfo() - .flatMap(chatRoomInfo -> writeChatRoomData( - chatRoomInfo.getId(), - chatHomeService - .getChatRoomData(chatRoomInfo.getId()) - .flatMapMany(chatRoomData -> chatRoomData.getMessages()) - ) - .then(Mono.just(chatRoomInfo)) - .doOnSuccess(emittedChatRoomInfo -> log.info("Stored {}", chatRoomInfo)) - .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))) - ) + return writeChatRoomInfo(chatHomeService.getChatRoomInfo()) + .flatMap(chatRoomInfo -> writeChatRoomData( + chatRoomInfo.getId(), + chatHomeService + .getChatRoomData(chatRoomInfo.getId()) + .flatMapMany(chatRoomData -> chatRoomData.getMessages()) + ) + .then() + .doOnSuccess(empty -> log.info("Stored {}", chatRoomInfo)) + .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))) .then() .doOnSuccess(empty -> log.info("Stored {}", chatHomeService)) .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable)); -- 2.20.1