diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-07-26 15:41:13 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-26 22:22:48 +0200 |
commit | 54a0a377e03074a27d7d9e84092487c55761b510 (patch) | |
tree | 2c6bf66efa9f5e997eec8a3eb45d5d3f42dce349 /lib/msgstore.go | |
parent | a1a549cb1e10d18e071695249b995e2dddfdac2a (diff) | |
download | aerc-54a0a377e03074a27d7d9e84092487c55761b510.zip |
threads: debounce client-side thread building
Debounce client-side thread building in the message store. Debouncing is
useful when multiple messages are loaded, i.e. when scrolling with
PgUp/PgDown.
Without the debouncing, all client-side threads will be built everytime
the message store is updated which creates a noticable lag in the
message list ui when client-side threading is activated.
The default debouncing delay can be changed by changing
'client-threads-delay' in the UI config section.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r-- | lib/msgstore.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index 61a6dd4..9d7f3af 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -5,6 +5,7 @@ import ( "time" "git.sr.ht/~rjarry/aerc/lib/sort" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -53,8 +54,8 @@ type MessageStore struct { triggerNewEmail func(*models.MessageInfo) triggerDirectoryChange func() - dirInfoUpdateDebounce *time.Timer - dirInfoUpdateDelay time.Duration + threadBuilderDebounce *time.Timer + threadBuilderDelay time.Duration } const MagicUid = 0xFFFFFFFF @@ -62,12 +63,10 @@ const MagicUid = 0xFFFFFFFF func NewMessageStore(worker *types.Worker, dirInfo *models.DirectoryInfo, defaultSortCriteria []*types.SortCriterion, - thread bool, clientThreads bool, + thread bool, clientThreads bool, clientThreadsDelay time.Duration, triggerNewEmail func(*models.MessageInfo), triggerDirectoryChange func()) *MessageStore { - dirInfoUpdateDelay := 5 * time.Second - if !dirInfo.Caps.Thread { clientThreads = true } @@ -95,8 +94,7 @@ func NewMessageStore(worker *types.Worker, triggerNewEmail: triggerNewEmail, triggerDirectoryChange: triggerDirectoryChange, - dirInfoUpdateDelay: dirInfoUpdateDelay, - dirInfoUpdateDebounce: time.NewTimer(dirInfoUpdateDelay), + threadBuilderDelay: clientThreadsDelay, } } @@ -386,7 +384,17 @@ func (store *MessageStore) runThreadBuilder() { store.builder.Update(msg) } } - store.Threads = store.builder.Threads(store.uids) + if store.threadBuilderDebounce != nil { + if store.threadBuilderDebounce.Stop() { + logging.Infof("thread builder debounced") + } + } + store.threadBuilderDebounce = time.AfterFunc(store.threadBuilderDelay, func() { + store.Threads = store.builder.Threads(store.uids) + if store.onUpdate != nil { + store.onUpdate(store) + } + }) } func (store *MessageStore) Delete(uids []uint32, |