You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/07/27 05:34:24 UTC

[GitHub] [james-project] quantranhong1999 commented on a change in pull request #554: JAMES-3516 Implement ThreadIdGuessingAlgorithm for Distributed module

quantranhong1999 commented on a change in pull request #554:
URL: https://github.com/apache/james-project/pull/554#discussion_r677131311



##########
File path: mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/StoreThreadIdGuessingAlgorithm.java
##########
@@ -0,0 +1,90 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one     *
+ * or more contributor license agreements.  See the NOTICE file   *
+ * distributed with this work for additional information          *
+ * regarding copyright ownership.  The ASF licenses this file     *
+ * to you under the Apache License, Version 2.0 (the              *
+ * "License"); you may not use this file except in compliance     *
+ * with the License.  You may obtain a copy of the License at     *
+ *                                                                *
+ * http://www.apache.org/licenses/LICENSE-2.0                     *
+ *                                                                *
+ * Unless required by applicable law or agreed to in writing,     *
+ * software distributed under the License is distributed on an    *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY         *
+ * KIND, either express or implied.  See the License for the      *
+ * specific language governing permissions and limitations        *
+ * under the License.                                             *
+ ******************************************************************/
+
+package org.apache.james.mailbox.cassandra;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.cassandra.mail.CassandraThreadDAO;
+import org.apache.james.mailbox.exception.ThreadNotFoundException;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.ThreadId;
+import org.apache.james.mailbox.store.mail.ThreadIdGuessingAlgorithm;
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mailbox.store.search.SearchUtil;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class StoreThreadIdGuessingAlgorithm implements ThreadIdGuessingAlgorithm {
+    private final MailboxManager mailboxManager;
+    private final CassandraThreadDAO threadDAO;
+
+    @Inject
+    public StoreThreadIdGuessingAlgorithm(MailboxManager mailboxManager, CassandraThreadDAO threadDAO) {
+        this.mailboxManager = mailboxManager;
+        this.threadDAO = threadDAO;
+    }
+
+    @Override
+    public Mono<ThreadId> guessThreadIdReactive(MessageId messageId, Optional<MimeMessageId> mimeMessageId, Optional<MimeMessageId> inReplyTo, Optional<List<MimeMessageId>> references, Optional<Subject> subject, MailboxSession session) {
+        Set<MimeMessageId> mimeMessageIds = buildMimeMessageIdSet(mimeMessageId, inReplyTo, references);
+        Optional<Subject> baseSubject = subject.map(value -> new Subject(SearchUtil.getBaseSubject(value.getValue())));
+        return Flux.from(threadDAO.selectSome(session.getUser(), mimeMessageIds))
+            .filter(pair -> pair.getLeft().equals(baseSubject))
+            .next()
+            .map(Pair::getRight)
+            .switchIfEmpty(Mono.just(ThreadId.fromBaseMessageId(messageId)))
+            .doOnSuccess(threadId -> threadDAO.insertSome(session.getUser(), mimeMessageIds, messageId, threadId, baseSubject));

Review comment:
       I tried .blockLast
   ![image](https://user-images.githubusercontent.com/55171818/127100264-52b81e33-2f22-4165-9c2f-83d8880c6538.png)
   And then test guessing threadId for two newly related messages (non message before):
   ![image](https://user-images.githubusercontent.com/55171818/127100406-edd20dbe-b74b-4f0c-872d-a8dcc62d2362.png)
   The test was green. It's look like guessThreadId using Cassandra is ok now. 
   
   But the getThread API using ElasticSearch do not work properly. Even I tried to plug SearchThreadIdGuessingAlgorithm to JMAP level module and the result using ES is not proper.
   The inmemory test using ScanningSearch is ok, so my guess problem is at ES. I will continue working on this.
   




-- 
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