summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-02-24 20:18:31 +0100
committerDrew DeVault <sir@cmpwn.com>2020-02-25 11:05:26 -0500
commit5dd0f454c197ccbce369ee88d47d5be8cd5e8265 (patch)
tree081b3b032afa6e945478a1e5bf1dfcf69b64fcb5
parent53d0c0a9030ce20ee98c2a0bdb221e73f647c16c (diff)
downloadaerc-5dd0f454c197ccbce369ee88d47d5be8cd5e8265.tar.gz
lib/msgstore: debounce directoryUpdateRequests
Apparently sending an event for every incoming messageInfo slows down
the application significantly.

Therefore this slows down the emmision rate, on the cost of being out of date
in some cases.
-rw-r--r--lib/msgstore.go20
-rw-r--r--worker/imap/worker.go2
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index ae58aaf..b1785c1 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -42,6 +42,9 @@ type MessageStore struct {
 
 	triggerNewEmail        func(*models.MessageInfo)
 	triggerDirectoryChange func()
+
+	dirInfoUpdateDebounce *time.Timer
+	dirInfoUpdateDelay    time.Duration
 }
 
 func NewMessageStore(worker *types.Worker,
@@ -50,6 +53,8 @@ func NewMessageStore(worker *types.Worker,
 	triggerNewEmail func(*models.MessageInfo),
 	triggerDirectoryChange func()) *MessageStore {
 
+	dirInfoUpdateDelay := 5 * time.Second
+
 	return &MessageStore{
 		Deleted:  make(map[uint32]interface{}),
 		DirInfo:  *dirInfo,
@@ -68,6 +73,9 @@ func NewMessageStore(worker *types.Worker,
 
 		triggerNewEmail:        triggerNewEmail,
 		triggerDirectoryChange: triggerDirectoryChange,
+
+		dirInfoUpdateDelay:    dirInfoUpdateDelay,
+		dirInfoUpdateDebounce: time.NewTimer(dirInfoUpdateDelay),
 	}
 }
 
@@ -267,9 +275,15 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 	}
 
 	if requestDirInfo {
-		store.worker.PostAction(&types.DirectoryInfoUpdateRequest{
-			Name: store.DirInfo.Name,
-		}, nil)
+		select {
+		case <-store.dirInfoUpdateDebounce.C:
+			store.worker.PostAction(&types.DirectoryInfoUpdateRequest{
+				Name: store.DirInfo.Name,
+			}, nil)
+			store.dirInfoUpdateDebounce.Reset(store.dirInfoUpdateDelay)
+		default:
+			// do nothing
+		}
 	}
 }
 
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index ddd95b6..1037f81 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -181,6 +181,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
 		w.handleAppendMessage(msg)
 	case *types.SearchDirectory:
 		w.handleSearchDirectory(msg)
+	case *types.DirectoryInfoUpdateRequest:
+		// not implemented
 	default:
 		reterr = errUnsupported
 	}
254408a385f90ffe212e85a7b405054f4e73f5e'>4254408a ^
3350c34a ^
f6fd7e1b ^



4254408a ^
3350c34a ^
f6fd7e1b ^


4254408a ^
3350c34a ^
f6fd7e1b ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89