You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "Arsnael (via GitHub)" <gi...@apache.org> on 2023/09/28 08:34:54 UTC

[GitHub] [james-project] Arsnael commented on a diff in pull request #1740: OpenSearch search index: upon move, GET then INDEX

Arsnael commented on code in PR #1740:
URL: https://github.com/apache/james-project/pull/1740#discussion_r1339731565


##########
mailbox/opensearch/src/main/java/org/apache/james/mailbox/opensearch/events/OpenSearchListeningMessageSearchIndex.java:
##########
@@ -131,7 +147,84 @@ public EnumSet<SearchCapabilities> getSupportedCapabilities(EnumSet<MessageCapab
             SearchCapabilities.AttachmentFileName,
             SearchCapabilities.PartialEmailMatch);
     }
-    
+
+    @Override
+    public Mono<Void> reactiveEvent(Event event) {
+        MailboxSession systemSession = sessionProvider.createSystemSession(event.getUsername());
+        return handleMailboxEvent(event, systemSession, (MailboxEvents.MailboxEvent) event)
+            .then(Mono.fromRunnable(() -> factory.endProcessingRequest(systemSession)));
+    }
+
+    private Mono<Void> handleMailboxEvent(Event event, MailboxSession session, MailboxEvents.MailboxEvent mailboxEvent) {
+        MailboxId mailboxId = mailboxEvent.getMailboxId();
+
+        if (event instanceof MailboxEvents.Added) {
+            MailboxEvents.Added addedEvent = (MailboxEvents.Added) event;
+
+            if (addedEvent.isMoved()) {
+                MailboxId movedFromMailboxId = addedEvent.movedFromMailboxId().get();
+                return Flux.fromIterable(addedEvent.getUids())
+                    .concatMap(messageUid -> addByIndexedDocument(movedFromMailboxId, addedEvent.getMailboxId(), messageUid, session))
+                    .onErrorResume(OpenSearchNotFoundException.class,
+                        notFoundException -> addByFetchMailboxMessage((MailboxEvents.Added) event, session, mailboxId))
+                    .thenEmpty(Mono.defer(() -> delete(session, movedFromMailboxId, addedEvent.getUids())));
+            } else {
+                return addByFetchMailboxMessage((MailboxEvents.Added) event, session, mailboxId);
+            }

Review Comment:
   Would have extracted that nested if in a method



##########
mailbox/api/src/main/java/org/apache/james/mailbox/events/MailboxEvents.java:
##########
@@ -415,10 +415,14 @@ public ImmutableSet<MessageId> getMessageIds() {
 
     class Expunged extends MetaDataHoldingEvent {
         private final Map<MessageUid, MessageMetaData> expunged;
+        private final Optional<MailboxId> movedToMailboxId;
 
-        public Expunged(MailboxSession.SessionId sessionId, Username username, MailboxPath path, MailboxId mailboxId, Map<MessageUid, MessageMetaData> uids, EventId eventId) {
+        public Expunged(MailboxSession.SessionId sessionId, Username username,
+                        MailboxPath path, MailboxId mailboxId, Map<MessageUid, MessageMetaData> uids,
+                        EventId eventId, Optional<MailboxId> movedToMailboxId) {
             super(sessionId, username, path, mailboxId, eventId);
             this.expunged = ImmutableMap.copyOf(uids);
+            this.movedToMailboxId = movedToMailboxId;

Review Comment:
   I don't think this field is useful as you only use the one from Added event when `isMoved` and we skip the Expunged one :)



-- 
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: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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