summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/msgstore.go20
1 files changed, 17 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
+		}
 	}
 }