imap: remove spurious checkmail when changing directories

I investigated why aerc felt so slow when changing directories with my
mailbox, and noticed that a spurious CheckMail is triggered whenever
OpenDirectory is called.

This happens because OpenDirectory does a Select(TheTargetMailbox),
which gets the server to reply a MailboxUpdate message for the target
directory, in turn triggering a (slow) CheckMail.

That CheckMail is completely useless, since the normal flow that follows
OpenDirectory involves a FetchDirectoryContents, which is what we need
to draw the message list (and not more).

This patch leverages a drainCloser object to ignore spurious messages
from the server, exactly like handle{Move,Delete}Messages do.

Some measurements to quantify the impact can be found in
  https://paste.sr.ht/~simartin/05011fb7615c5b60bf12bb36fc9d08221550e403
TL;DR: The latency of Shift+K => Shift+J to go to a large (8.6k message)
folder and back is divided by ~7.

Signed-off-by: Simon Martin <simon@nasilyan.com>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Simon Martin
2025-03-10 20:37:17 +01:00
committed by Robin Jarry
parent 3d6d5e5c09
commit 96ccb183fb

View File

@@ -10,6 +10,11 @@ import (
)
func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
// The SELECT we'll issue might trigger MailboxStatus replies from the
// server, causing unnecessary CheckMail commands. Let's ignore those.
drain := imapw.drainUpdates()
defer drain.Close()
imapw.worker.Debugf("Opening %s", msg.Directory)
sel, err := imapw.client.Select(msg.Directory, false)