diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-09-19 19:49:15 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-09-20 21:10:35 +0200 |
commit | 9fdc7acf5b4842b95ab2b53c9baf69ab085b9e79 (patch) | |
tree | d101bdd34df65ed36432ed121481c9ee477e3a67 /worker/imap | |
parent | a91009edf73e37b3c4f9ae37e810fcb7b466e277 (diff) | |
download | aerc-9fdc7acf5b4842b95ab2b53c9baf69ab085b9e79.tar.gz |
cache: fetch flags from UI
When cached headers are fetched, an action is posted back to the Worker
to immediately fetch the flags for the message from the server (we can't
know the flags state, therefore it's not cached). When scrolling, a lag
occurs when loading cached headers because the n+1 message has to wait
for the flag request to return before the cached headers are retrieved.
Collect the message UIDs in the UI that need flags, and fetch them based
off a debounce timer in a single request. Post the action from the UI to
eliminate an (ugly) go routine in the worker.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/imap')
-rw-r--r-- | worker/imap/cache.go | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/worker/imap/cache.go b/worker/imap/cache.go index 3c807c50..17a622d6 100644 --- a/worker/imap/cache.go +++ b/worker/imap/cache.go @@ -85,7 +85,7 @@ func (w *IMAPWorker) cacheHeader(mi *models.MessageInfo) { func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 { logging.Debugf("Retrieving headers from cache: %v", msg.Uids) - var need, found []uint32 + var need []uint32 uv := fmt.Sprintf("%d", w.selected.UidValidity) for _, uid := range msg.Uids { u := fmt.Sprintf("%d", uid) @@ -118,17 +118,11 @@ func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 { Uid: ch.Uid, RFC822Headers: hdr, } - found = append(found, uid) logging.Debugf("located cached header %s.%s", uv, u) w.worker.PostMessage(&types.MessageInfo{ - Message: types.RespondTo(msg), - Info: mi, - }, nil) - } - if len(found) > 0 { - // Post in a separate goroutine to prevent deadlocking - go w.worker.PostAction(&types.FetchMessageFlags{ - Uids: found, + Message: types.RespondTo(msg), + Info: mi, + NeedsFlags: true, }, nil) } return need |