maildir: defer the count of recent messages

Since commit 01c96e78df ("Update DirectoryInfo handling for maildir"),
flags are checked for every message of a folder when entering it.
Iterating over all messages of a folder takes a long time for large
collections of emails.

Only count the number of messages and state that the directory info
counts are not accurate. Defer the parsing of message flags in
a goroutine to have a more responsive UI.

Fixes: https://todo.sr.ht/~rjarry/aerc/16
Suggested-by: Koni Marti <koni.marti@gmail.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Robin Jarry 2022-01-28 13:23:25 +01:00
parent a5c046efe3
commit 622802d3a5
1 changed files with 32 additions and 25 deletions

View File

@ -132,7 +132,7 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
// total unread // total unread
Unseen: 0, Unseen: 0,
AccurateCounts: true, AccurateCounts: false,
} }
dir := w.c.Dir(name) dir := w.c.Dir(name)
@ -143,6 +143,10 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
return dirInfo return dirInfo
} }
dirInfo.Exists = len(uids)
go func() {
info := dirInfo
for _, uid := range uids { for _, uid := range uids {
message, err := w.c.Message(dir, uid) message, err := w.c.Message(dir, uid)
if err != nil { if err != nil {
@ -161,14 +165,17 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
} }
} }
if !seen { if !seen {
dirInfo.Unseen++ info.Unseen++
} }
if w.c.IsRecent(uid) { if w.c.IsRecent(uid) {
dirInfo.Recent++ info.Recent++
} }
} }
dirInfo.Unseen += dirInfo.Recent info.Unseen += info.Recent
dirInfo.Exists = len(uids) + dirInfo.Recent info.Exists += info.Recent
info.AccurateCounts = true
}()
return dirInfo return dirInfo
} }