1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-02-22 23:23:57 +01:00
aerc/worker/notmuch/eventhandlers.go
Jason Cox b03750473d notmuch: reload all changed messages on DB change
This reverts commit c56649fe52.

As discussed in the aerc-devel thread for the reverted patch, the
performance improvement comes with an issue: changes to message tags are
no longer immediately reflected in the UI. This issue occurs whether the
tags are modified from within aerc or externally with the notmuch CLI.
The message list also flickers any time tag changes are made.

Further, commit c36ed72e4a ("notmuch: speed up lastmod query")
dramatically reduces the number of messages which are re-indexed when
the database changes, likely eliminating the need for the reverted
performance improvement anyway.

Fixes: c56649fe52 ("notmuch: don't reload all message on change")
Link: https://lists.sr.ht/~rjarry/aerc-devel/patches/53729
Link: https://lists.sr.ht/~rjarry/aerc-devel/patches/54028
Reported-by: Robin Dapp <rdapp@modk.org>
Reported-by: Ryan Winograd <ryan@thewinograds.com>
Signed-off-by: Jason Cox <me@jasoncarloscox.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-08-20 09:29:22 +02:00

92 lines
1.9 KiB
Go

//go:build notmuch
// +build notmuch
package notmuch
import (
"context"
"fmt"
"path/filepath"
"strconv"
"git.sr.ht/~rjarry/aerc/lib/log"
"git.sr.ht/~rjarry/aerc/worker/types"
)
func (w *worker) handleNotmuchEvent() error {
err := w.db.Connect()
if err != nil {
return err
}
defer w.db.Close()
err = w.updateDirCounts()
if err != nil {
return err
}
err = w.updateChangedMessages()
if err != nil {
return err
}
w.emitLabelList()
return nil
}
func (w *worker) updateDirCounts() error {
if w.store != nil {
folders, err := w.store.FolderMap()
if err != nil {
w.w.Errorf("failed listing directories: %v", err)
return err
}
for name := range folders {
folder := filepath.Join(w.maildirAccountPath, name)
query := fmt.Sprintf("folder:%s", strconv.Quote(folder))
w.w.PostMessage(&types.DirectoryInfo{
Info: w.getDirectoryInfo(name, query),
Refetch: w.query == query,
}, nil)
}
}
for name, query := range w.nameQueryMap {
w.w.PostMessage(&types.DirectoryInfo{
Info: w.getDirectoryInfo(name, query),
Refetch: w.query == query,
}, nil)
}
for name, query := range w.dynamicNameQueryMap {
w.w.PostMessage(&types.DirectoryInfo{
Info: w.getDirectoryInfo(name, query),
Refetch: w.query == query,
}, nil)
}
return nil
}
func (w *worker) updateChangedMessages() error {
newState := w.db.State()
if newState == w.state {
return nil
}
w.w.Logger.Debugf("State change: %d to %d", w.state, newState)
query := fmt.Sprintf("lastmod:%d..%d and (%s)", w.state, newState, w.query)
uids, err := w.uidsFromQuery(context.TODO(), query)
if err != nil {
return fmt.Errorf("Couldn't get updates messages: %w", err)
}
for _, uid := range uids {
m, err := w.msgFromUid(uid)
if err != nil {
log.Errorf("%s", err)
continue
}
err = w.emitMessageInfo(m, nil)
if err != nil {
log.Errorf("%s", err)
}
}
w.state = newState
return nil
}