vttranlina commented on code in PR #997:
URL: https://github.com/apache/james-project/pull/997#discussion_r880154398


##########
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java:
##########
@@ -172,19 +177,21 @@ private Mono<Void> 
manageApplicableFlagsOnFlagsUpdate(CassandraId mailboxId, Lis
     }
 
     private Mono<Void> updateDeletedOnFlagsUpdate(CassandraId mailboxId, 
List<UpdatedFlags> updatedFlags) {
-        return Flux.fromIterable(updatedFlags)
-            .concatMap(flags -> updateDeletedOnFlagsUpdate(mailboxId, flags))
-            .then();
-    }
+        List<MessageUid> addDeletedUids = updatedFlags
+            .stream()
+            .filter(flag -> flag.isModifiedToSet(Flags.Flag.DELETED))
+            .map(UpdatedFlags::getUid)
+            .collect(Collectors.toList());
+        List<MessageUid> removeDeletedUids = updatedFlags
+            .stream()
+            .filter(flag -> flag.isModifiedToUnset(Flags.Flag.DELETED))
+            .map(UpdatedFlags::getUid)
+            .collect(Collectors.toList());

Review Comment:
   ```suggestion
           ImmutableList.Builder<MessageUid> addDeletedUidsBuilder = 
ImmutableList.builder();
           ImmutableList.Builder<MessageUid> removeDeletedUidsBuilder = 
ImmutableList.builder();
   
           updatedFlags
               .forEach(flag -> {
                   if (flag.isModifiedToSet(Flags.Flag.DELETED)) {
                       addDeletedUidsBuilder.add(flag.getUid());
                   } else if (flag.isModifiedToUnset(Flags.Flag.DELETED)) {
                       removeDeletedUidsBuilder.add(flag.getUid());
                   }
               });
   ```
   it will avoid re-stream, re-filter?



##########
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java:
##########
@@ -292,26 +313,46 @@ private Mono<Void> checkDeletedOnAdd(CassandraId 
mailboxId, Flags flags, Message
         return Mono.empty();
     }
 
+    private Mono<Void> checkDeletedOnAdd(CassandraId mailboxId, 
Collection<MailboxMessage> mailboxMessages) {
+        return deletedMessageDAO.addDeleted(mailboxId, 
mailboxMessages.stream().filter(message -> 
message.createFlags().contains(Flags.Flag.DELETED))
+            .map(MailboxMessage::getUid)
+            .collect(Collectors.toList()));
+    }
+
     private Mono<Void> updateFirstUnseenOnDelete(CassandraId mailboxId, Flags 
flags, MessageUid uid) {
         if (flags.contains(Flags.Flag.SEEN)) {
             return Mono.empty();
         }
         return firstUnseenDAO.removeUnread(mailboxId, uid);
     }
 
-    private Mono<Void> updateFirstUnseenOnFlagsUpdate(CassandraId mailboxId, 
List<UpdatedFlags> updatedFlags) {
-        return Flux.fromIterable(updatedFlags)
-            .concatMap(flags -> updateFirstUnseenOnFlagsUpdate(mailboxId, 
flags))
-            .then();
+    private Mono<Void> updateFirstUnseenOnDeleteWithMetadata(CassandraId 
mailboxId, Collection<MessageMetaData> metaDatas) {
+        return firstUnseenDAO.removeUnread(mailboxId, 
metaDatas.stream().filter(metaData -> 
!metaData.getFlags().contains(Flags.Flag.SEEN))
+            .map(MessageMetaData::getUid)
+            .collect(Collectors.toList()));
     }
 
-    private Mono<Void> updateFirstUnseenOnFlagsUpdate(CassandraId mailboxId, 
UpdatedFlags updatedFlags) {
-        if (updatedFlags.isModifiedToUnset(Flags.Flag.SEEN)) {
-            return firstUnseenDAO.addUnread(mailboxId, updatedFlags.getUid());
-        }
-        if (updatedFlags.isModifiedToSet(Flags.Flag.SEEN)) {
-            return firstUnseenDAO.removeUnread(mailboxId, 
updatedFlags.getUid());
-        }
-        return Mono.empty();
+    private Mono<Void> updateFirstUnseenOnDelete(CassandraId mailboxId, 
Collection<ComposedMessageIdWithMetaData> composedMessageIdWithMetaData) {
+        return firstUnseenDAO.removeUnread(mailboxId, 
composedMessageIdWithMetaData.stream().filter(composeId -> 
!composeId.getFlags().contains(Flags.Flag.SEEN))
+            .map(composeId -> composeId.getComposedMessageId().getUid())
+            .collect(Collectors.toList()));
+    }
+
+    private Mono<Void> updateFirstUnseenOnFlagsUpdate(CassandraId mailboxId, 
List<UpdatedFlags> updatedFlags) {
+        List<MessageUid> addUnreadUids = updatedFlags

Review Comment:
   similar



##########
mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraIndexTableHandler.java:
##########
@@ -262,19 +275,21 @@ private Mono<Void> 
manageUnseenMessageCountsOnFlagsUpdate(CassandraId mailboxId,
     }
 
     private Mono<Void> manageRecentOnFlagsUpdate(CassandraId mailboxId, 
List<UpdatedFlags> updatedFlags) {
-        return Flux.fromIterable(updatedFlags)
-            .concatMap(flags -> manageRecentOnFlagsUpdate(mailboxId, flags))
-            .then();
-    }
+        List<MessageUid> addRecentUids = updatedFlags

Review Comment:
   similar 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to