You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/05/28 01:16:17 UTC

[james-project] 02/07: [PERFORMANCE] Further reactify setMessages update to outbox

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit cb84164f41e538de92135d7985b7677ca7c980bb
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sun May 23 10:20:27 2021 +0700

    [PERFORMANCE] Further reactify setMessages update to outbox
    
    Use the reactive version of getMessages.
---
 .../jmap/draft/methods/SetMessagesUpdateProcessor.java    | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
index 9172b33..b550e32 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessor.java
@@ -326,13 +326,8 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
 
     private Mono<SetMessagesResponse.Builder> sendMessageWhenOutboxInTargetMailboxIds(Set<MailboxId> outboxes, MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession) {
         if (isTargetingOutbox(outboxes, listTargetMailboxIds(updateMessagePatch))) {
-            return Mono.fromCallable(() -> {
-                Optional<MessageResult> maybeMessageToSend =
-                    messageIdManager.getMessage(messageId, FetchGroup.FULL_CONTENT, mailboxSession)
-                        .stream()
-                        .findFirst();
-                if (maybeMessageToSend.isPresent()) {
-                    MessageResult messageToSend = maybeMessageToSend.get();
+            return Mono.from(messageIdManager.getMessagesReactive(ImmutableList.of(messageId), FetchGroup.FULL_CONTENT, mailboxSession))
+                .flatMap(messageToSend -> Mono.fromCallable(() -> {
                     MailImpl mail = buildMailFromMessage(messageToSend);
                     Optional<Username> fromUser = mail.getMaybeSender()
                         .asOptional()
@@ -341,10 +336,8 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
                     messageSender.sendMessage(messageId, mail, mailboxSession);
                     referenceUpdater.updateReferences(messageToSend.getHeaders(), mailboxSession);
                     return SetMessagesResponse.builder();
-                } else {
-                    return addMessageIdNotFoundToResponse(messageId);
-                }
-            }).subscribeOn(Schedulers.elastic());
+                }).subscribeOn(Schedulers.elastic()))
+                .switchIfEmpty(Mono.just(addMessageIdNotFoundToResponse(messageId)));
         }
         return Mono.just(SetMessagesResponse.builder());
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org