summaryrefslogtreecommitdiff
path: root/lib/threadbuilder.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-26 15:41:13 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-26 22:22:48 +0200
commit54a0a377e03074a27d7d9e84092487c55761b510 (patch)
tree2c6bf66efa9f5e997eec8a3eb45d5d3f42dce349 /lib/threadbuilder.go
parenta1a549cb1e10d18e071695249b995e2dddfdac2a (diff)
downloadaerc-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/threadbuilder.go')
-rw-r--r--lib/threadbuilder.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go
index 59abd2f..ce56afe 100644
--- a/lib/threadbuilder.go
+++ b/lib/threadbuilder.go
@@ -1,6 +1,7 @@
package lib
import (
+ "sync"
"time"
"git.sr.ht/~rjarry/aerc/logging"
@@ -10,6 +11,7 @@ import (
)
type ThreadBuilder struct {
+ sync.Mutex
threadBlocks map[uint32]jwz.Threadable
messageidToUid map[string]uint32
seen map[uint32]bool
@@ -27,6 +29,9 @@ func NewThreadBuilder() *ThreadBuilder {
// Uids returns the uids in threading order
func (builder *ThreadBuilder) Uids() []uint32 {
+ builder.Lock()
+ defer builder.Unlock()
+
if builder.threadedUids == nil {
return []uint32{}
}
@@ -35,6 +40,9 @@ func (builder *ThreadBuilder) Uids() []uint32 {
// Update updates the thread builder with a new message header
func (builder *ThreadBuilder) Update(msg *models.MessageInfo) {
+ builder.Lock()
+ defer builder.Unlock()
+
if msg != nil {
if threadable := newThreadable(msg); threadable != nil {
builder.messageidToUid[threadable.MessageThreadID()] = msg.Uid
@@ -45,6 +53,9 @@ func (builder *ThreadBuilder) Update(msg *models.MessageInfo) {
// Threads returns a slice of threads for the given list of uids
func (builder *ThreadBuilder) Threads(uids []uint32) []*types.Thread {
+ builder.Lock()
+ defer builder.Unlock()
+
start := time.Now()
threads := builder.buildAercThreads(builder.generateStructure(uids), uids)