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 /lib/msgstore.go | |
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 'lib/msgstore.go')
-rw-r--r-- | lib/msgstore.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index a545f62f..58c5faba 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -48,6 +48,10 @@ type MessageStore struct { pendingHeaders map[uint32]interface{} worker *types.Worker + needsFlags []uint32 + fetchFlagsDebounce *time.Timer + fetchFlagsDelay time.Duration + triggerNewEmail func(*models.MessageInfo) triggerDirectoryChange func() @@ -91,6 +95,9 @@ func NewMessageStore(worker *types.Worker, pendingHeaders: make(map[uint32]interface{}), worker: worker, + needsFlags: []uint32{}, + fetchFlagsDelay: 50 * time.Millisecond, + triggerNewEmail: triggerNewEmail, triggerDirectoryChange: triggerDirectoryChange, @@ -251,6 +258,10 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { } else if msg.Info.Envelope != nil { store.Messages[msg.Info.Uid] = msg.Info } + if msg.NeedsFlags { + store.needsFlags = append(store.needsFlags, msg.Info.Uid) + store.fetchFlags() + } seen := false recent := false for _, flag := range msg.Info.Flags { @@ -752,3 +763,15 @@ func (store *MessageStore) Capabilities() *models.Capabilities { func (store *MessageStore) SelectedIndex() int { return store.FindIndexByUid(store.selectedUid) } + +func (store *MessageStore) fetchFlags() { + if store.fetchFlagsDebounce != nil { + store.fetchFlagsDebounce.Stop() + } + store.fetchFlagsDebounce = time.AfterFunc(store.fetchFlagsDelay, func() { + store.worker.PostAction(&types.FetchMessageFlags{ + Uids: store.needsFlags, + }, nil) + store.needsFlags = []uint32{} + }) +} |