You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2020/10/14 02:31:32 UTC
[james-project] 06/22: JAMES-3277 StoreMessageIdManager::setFlags
should read mailboxes only once
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 644e4e7839b556709ef8c8d5a96053cb0016abca
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Oct 12 12:35:13 2020 +0700
JAMES-3277 StoreMessageIdManager::setFlags should read mailboxes only once
They were previously read 2 times:
- For right enforcement
- For retrieving information to dispatch
By reading the mailboxes upfront we can be reading them only once.
---
.../james/mailbox/store/StoreMessageIdManager.java | 27 +++++++++++++++++-----
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 1a29de9..74aebbb 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -119,12 +119,20 @@ public class StoreMessageIdManager implements MessageIdManager {
@Override
public void setFlags(Flags newState, MessageManager.FlagsUpdateMode replace, MessageId messageId, List<MailboxId> mailboxIds, MailboxSession mailboxSession) throws MailboxException {
MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
+ MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
+
+ int concurrency = 4;
+ List<Mailbox> targetMailboxes = Flux.fromIterable(mailboxIds)
+ .flatMap(mailboxMapper::findMailboxById, concurrency)
+ .collect(Guavate.toImmutableList())
+ .subscribeOn(Schedulers.elastic())
+ .block();
- MailboxReactorUtils.block(assertRightsOnMailboxIds(mailboxIds, mailboxSession, Right.Write));
+ assertRightsOnMailboxes(targetMailboxes, mailboxSession, Right.Write);
Multimap<MailboxId, UpdatedFlags> updatedFlags = messageIdMapper.setFlags(messageId, mailboxIds, newState, replace);
for (Map.Entry<MailboxId, Collection<UpdatedFlags>> entry : updatedFlags.asMap().entrySet()) {
- dispatchFlagsChange(mailboxSession, entry.getKey(), ImmutableList.copyOf(entry.getValue()));
+ dispatchFlagsChange(mailboxSession, entry.getKey(), ImmutableList.copyOf(entry.getValue()), targetMailboxes);
}
}
@@ -352,16 +360,23 @@ public class StoreMessageIdManager implements MessageIdManager {
.then());
}
- private void dispatchFlagsChange(MailboxSession mailboxSession, MailboxId mailboxId, ImmutableList<UpdatedFlags> updatedFlags) throws MailboxException {
+ private void dispatchFlagsChange(MailboxSession mailboxSession, MailboxId mailboxId, ImmutableList<UpdatedFlags> updatedFlags,
+ List<Mailbox> knownMailboxes) throws MailboxException {
if (updatedFlags.stream().anyMatch(UpdatedFlags::flagsChanged)) {
- mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId)
- .flatMap(mailbox -> eventBus.dispatch(EventFactory.flagsUpdated()
+ Mailbox mailbox = knownMailboxes.stream()
+ .filter(knownMailbox -> knownMailbox.getMailboxId().equals(mailboxId))
+ .findFirst()
+ .orElseGet(Throwing.supplier(() -> MailboxReactorUtils.block(mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)
+ .findMailboxById(mailboxId)
+ .subscribeOn(Schedulers.elastic())))
+ .sneakyThrow());
+ eventBus.dispatch(EventFactory.flagsUpdated()
.randomEventId()
.mailboxSession(mailboxSession)
.mailbox(mailbox)
.updatedFlags(updatedFlags)
.build(),
- new MailboxIdRegistrationKey(mailboxId)))
+ new MailboxIdRegistrationKey(mailboxId))
.subscribeOn(Schedulers.elastic())
.block();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org