You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2023/06/15 15:52:59 UTC
[james-project] 01/03: JAMES-3911 JPA: optimize applicable flags with a native query (#1593)
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch 3.8.x
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit e09ee06d56f7565fd5abb10aa6469a037b74d001
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Thu Jun 15 12:05:35 2023 +0700
JAMES-3911 JPA: optimize applicable flags with a native query (#1593)
SELECT P99 6249ms => 2596ms
---
.../org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
index e30765683b..3e6a501793 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
@@ -29,6 +29,7 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
+import org.apache.james.mailbox.ApplicableFlagBuilder;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.ModSeq;
import org.apache.james.mailbox.exception.MailboxException;
@@ -50,7 +51,6 @@ import org.apache.james.mailbox.model.UpdatedFlags;
import org.apache.james.mailbox.store.FlagsUpdateCalculator;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.utils.ApplicableFlagCalculator;
import org.apache.openjpa.persistence.ArgumentException;
import com.github.fge.lambdas.Throwing;
@@ -340,9 +340,13 @@ public class JPAMessageMapper extends JPATransactionalMapper implements MessageM
@Override
public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
- int maxBatchSize = -1;
- return new ApplicableFlagCalculator(findMessagesInMailbox((JPAId) mailbox.getMailboxId(), maxBatchSize))
- .computeApplicableFlags();
+ JPAId jpaId = (JPAId) mailbox.getMailboxId();
+ ApplicableFlagBuilder builder = ApplicableFlagBuilder.builder();
+ List<String> flags = getEntityManager().createNativeQuery("SELECT DISTINCT USERFLAG_NAME FROM JAMES_MAIL_USERFLAG WHERE MAILBOX_ID=?")
+ .setParameter(1, jpaId.getRawId())
+ .getResultList();
+ flags.forEach(builder::add);
+ return builder.build();
}
private MessageMetaData copy(Mailbox mailbox, MessageUid uid, ModSeq modSeq, MailboxMessage original)
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org