Skip to content

Commit

Permalink
fixup! perf(imap): Reduce number of STATUS commands for background ma…
Browse files Browse the repository at this point in the history
…ilbox sync

Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Jul 6, 2023
1 parent f0b4718 commit d4d77a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Db/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function hasLocks(int $now): bool {
* @return MailboxStats
*/
public function getStats(): MailboxStats {
return new MailboxStats($this->getMessages(), $this->getUnseen(), $this->getMyAcls());
return new MailboxStats($this->getMessages(), $this->getUnseen());
}

#[ReturnTypeWillChange]
Expand Down
2 changes: 1 addition & 1 deletion lib/IMAP/FolderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getFolders(Account $account, Horde_Imap_Client_Socket $client,
$attributes = array_flip(array_map('strtolower', $mailbox['attributes']));
if (isset($attributes['\\nonexistent'])) {
// Ignore mailbox that does not exist, similar to \Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS mode
return null;
return false;
}
// This is a special folder that must not be shown
return !in_array($mailbox['mailbox']->utf8, self::DOVECOT_SIEVE_FOLDERS, true);
Expand Down
8 changes: 5 additions & 3 deletions lib/IMAP/MailboxSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,20 @@ private function isMailboxShared(?Horde_Imap_Client_Namespace_List $namespaces,
}

private function syncMailboxStatus(mixed $mailboxes, ?string $personalNamespace, \Horde_Imap_Client_Socket $client): void {
[$sync, $doNotSync] = array_reduce($mailboxes, function (array $carry, Mailbox $mailbox) use ($personalNamespace) {
/** @var array{0: Mailbox[], 1: Mailbox[]} */
[$sync, $doNotSync] = array_reduce($mailboxes, function (array $carry, Mailbox $mailbox) use ($personalNamespace): array {
/** @var array{0: Mailbox[], 1: Mailbox[]} $carry */
[$sync, $doNotSync] = $carry;
$inboxName = $personalNamespace === null ? "INBOX" : ($personalNamespace . $mailbox->getDelimiter() . "INBOX");
if ($inboxName === $mailbox->getName() || $mailbox->getSyncInBackground()) {
return [
[...$sync, $mailbox],
$sync + [$mailbox],
$doNotSync,
];
}
return [
$sync,
[...$doNotSync, $mailbox],
$doNotSync + [$mailbox],
];
}, [[], []]);

Expand Down

0 comments on commit d4d77a2

Please sign in to comment.