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 532d29bc4fa42db895551534df7b1d59fe2ef08c
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri Dec 6 10:17:44 2019 +0700

    JAMES-2992 Rework MessageFastViewFactory accordingly
    
    We can now avoid some collection copy and inline some extracted methods
---
 .../model/message/view/MessageFastViewFactory.java   | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
index b212c11..cc11416 100644
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageFastViewFactory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.inject.Inject;
 
@@ -118,30 +119,27 @@ public class MessageFastViewFactory implements 
MessageViewFactory<MessageFastVie
 
     @Override
     public List<MessageFastView> fromMessageIds(List<MessageId> messageIds, 
MailboxSession mailboxSession) {
+        ImmutableSet<MessageId> messageIdSet = ImmutableSet.copyOf(messageIds);
         return Mono.from(fastViewProjection.retrieve(messageIds))
-            .flatMapMany(fastProjections -> gatherMessageViews(messageIds, 
mailboxSession, fastProjections))
+            .flatMapMany(fastProjections -> gatherMessageViews(messageIdSet, 
mailboxSession, fastProjections))
             .collectList()
             .subscribeOn(Schedulers.boundedElastic())
             .block();
     }
 
-    private Flux<MessageFastView> gatherMessageViews(List<MessageId> 
messageIds, MailboxSession mailboxSession,
+    private Flux<MessageFastView> gatherMessageViews(Set<MessageId> 
messageIds, MailboxSession mailboxSession,
                                                      Map<MessageId, 
MessageFastViewPrecomputedProperties> fastProjections) {
+        Set<MessageId> withPreview = fastProjections.keySet();
+        Set<MessageId> withoutPreviews = Sets.difference(messageIds, 
fastProjections.keySet());
         return Flux.merge(
-                fetch(ImmutableList.copyOf(fastProjections.keySet()), 
FetchGroup.HEADERS, mailboxSession)
+                fetch(withPreview, FetchGroup.HEADERS, mailboxSession)
                     .map(messageResults -> 
Helpers.toMessageViews(messageResults, new 
FromMessageResultAndPreview(blobManager, fastProjections))),
-                fetch(withoutPreviews(messageIds, fastProjections), 
FetchGroup.FULL_CONTENT, mailboxSession)
+                fetch(withoutPreviews, FetchGroup.FULL_CONTENT, mailboxSession)
                     .map(messageResults -> 
Helpers.toMessageViews(messageResults, 
messageFullViewFactory::fromMessageResults)))
             .flatMap(Flux::fromIterable);
     }
 
-    private List<MessageId> withoutPreviews(List<MessageId> messageIds, 
Map<MessageId, MessageFastViewPrecomputedProperties> fastProjections) {
-        return ImmutableList.copyOf(Sets.difference(
-            ImmutableSet.copyOf(messageIds),
-            fastProjections.keySet()));
-    }
-
-    private Mono<List<MessageResult>> fetch(List<MessageId> messageIds, 
FetchGroup fetchGroup, MailboxSession mailboxSession) {
+    private Mono<List<MessageResult>> fetch(Collection<MessageId> messageIds, 
FetchGroup fetchGroup, MailboxSession mailboxSession) {
         return Mono.fromCallable(() -> 
messageIdManager.getMessages(messageIds, fetchGroup, mailboxSession))
             .onErrorResume(MailboxException.class, ex -> {
                 LOGGER.error("cannot read messages {}", messageIds, ex);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to