You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2019/01/29 12:15:32 UTC

[2/3] james-project git commit: JAMES-2630 fix ordering of message attachment issue

JAMES-2630 fix ordering of message attachment issue


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c617824d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c617824d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c617824d

Branch: refs/heads/master
Commit: c617824dcdd84842b74c28668d6fc590987df1ea
Parents: bad5da4
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Jan 29 10:12:23 2019 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Jan 29 13:14:01 2019 +0100

----------------------------------------------------------------------
 .../mailbox/cassandra/mail/AttachmentLoader.java      | 14 +++++++++-----
 .../cassandra/mail/CassandraMessageMapper.java        |  6 ++----
 2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c617824d/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
index d57e99a..b3eef40 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
@@ -27,6 +27,7 @@ import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 
+import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 import reactor.core.publisher.Flux;
@@ -41,22 +42,25 @@ public class AttachmentLoader {
     }
 
     public Mono<SimpleMailboxMessage> addAttachmentToMessage(Pair<MessageWithoutAttachment, Stream<MessageAttachmentRepresentation>> messageRepresentation, MessageMapper.FetchType fetchType) {
+        return loadAttachments(messageRepresentation.getRight(), fetchType)
+            .map(attachments -> messageRepresentation.getLeft().toMailboxMessage(attachments));
+    }
 
+    private Mono<List<MessageAttachment>> loadAttachments(Stream<MessageAttachmentRepresentation> messageAttachmentRepresentations, MessageMapper.FetchType fetchType) {
         if (fetchType == MessageMapper.FetchType.Body || fetchType == MessageMapper.FetchType.Full) {
-            return getAttachments(messageRepresentation.getRight().collect(ImmutableList.toImmutableList()))
-                        .map(attachments -> messageRepresentation.getLeft().toMailboxMessage(attachments));
+            return getAttachments(messageAttachmentRepresentations.collect(Guavate.toImmutableList()));
         } else {
-            return Mono.just(messageRepresentation.getLeft().toMailboxMessage(ImmutableList.of()));
+            return Mono.just(ImmutableList.of());
         }
     }
 
     @VisibleForTesting
     Mono<List<MessageAttachment>> getAttachments(List<MessageAttachmentRepresentation> attachmentRepresentations) {
         return Flux.fromIterable(attachmentRepresentations)
-                .flatMap(attachmentRepresentation ->
+                .flatMapSequential(attachmentRepresentation ->
                         attachmentMapper.getAttachmentsAsMono(attachmentRepresentation.getAttachmentId())
                             .map(attachment -> constructMessageAttachment(attachment, attachmentRepresentation)))
-                .collectList();
+                .collect(Guavate.toImmutableList());
     }
 
     private MessageAttachment constructMessageAttachment(Attachment attachment, MessageAttachmentRepresentation messageAttachmentRepresentation) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/c617824d/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index d2c4006..af3d7dc 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -24,7 +24,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-import java.util.function.Function;
 
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
@@ -163,9 +162,8 @@ public class CassandraMessageMapper implements MessageMapper {
     public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange messageRange, FetchType ftype, int max) throws MailboxException {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
         return retrieveMessages(retrieveMessageIds(mailboxId, messageRange), ftype, Limit.from(max))
-            .map(simpleMailboxMessage -> (MailboxMessage) simpleMailboxMessage)
-            .collectSortedList(Comparator.comparing(MailboxMessage::getUid))
-            .flatMapIterable(Function.identity())
+            .map(MailboxMessage.class::cast)
+            .sort(Comparator.comparing(MailboxMessage::getUid))
             .toIterable()
             .iterator();
     }


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