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.
This commit is contained in:
parent
53d0c0a903
commit
5dd0f454c1
|
@ -42,6 +42,9 @@ type MessageStore struct {
|
||||||
|
|
||||||
triggerNewEmail func(*models.MessageInfo)
|
triggerNewEmail func(*models.MessageInfo)
|
||||||
triggerDirectoryChange func()
|
triggerDirectoryChange func()
|
||||||
|
|
||||||
|
dirInfoUpdateDebounce *time.Timer
|
||||||
|
dirInfoUpdateDelay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMessageStore(worker *types.Worker,
|
func NewMessageStore(worker *types.Worker,
|
||||||
|
@ -50,6 +53,8 @@ func NewMessageStore(worker *types.Worker,
|
||||||
triggerNewEmail func(*models.MessageInfo),
|
triggerNewEmail func(*models.MessageInfo),
|
||||||
triggerDirectoryChange func()) *MessageStore {
|
triggerDirectoryChange func()) *MessageStore {
|
||||||
|
|
||||||
|
dirInfoUpdateDelay := 5 * time.Second
|
||||||
|
|
||||||
return &MessageStore{
|
return &MessageStore{
|
||||||
Deleted: make(map[uint32]interface{}),
|
Deleted: make(map[uint32]interface{}),
|
||||||
DirInfo: *dirInfo,
|
DirInfo: *dirInfo,
|
||||||
|
@ -68,6 +73,9 @@ func NewMessageStore(worker *types.Worker,
|
||||||
|
|
||||||
triggerNewEmail: triggerNewEmail,
|
triggerNewEmail: triggerNewEmail,
|
||||||
triggerDirectoryChange: triggerDirectoryChange,
|
triggerDirectoryChange: triggerDirectoryChange,
|
||||||
|
|
||||||
|
dirInfoUpdateDelay: dirInfoUpdateDelay,
|
||||||
|
dirInfoUpdateDebounce: time.NewTimer(dirInfoUpdateDelay),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,9 +275,15 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if requestDirInfo {
|
if requestDirInfo {
|
||||||
|
select {
|
||||||
|
case <-store.dirInfoUpdateDebounce.C:
|
||||||
store.worker.PostAction(&types.DirectoryInfoUpdateRequest{
|
store.worker.PostAction(&types.DirectoryInfoUpdateRequest{
|
||||||
Name: store.DirInfo.Name,
|
Name: store.DirInfo.Name,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
store.dirInfoUpdateDebounce.Reset(store.dirInfoUpdateDelay)
|
||||||
|
default:
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
|
||||||
w.handleAppendMessage(msg)
|
w.handleAppendMessage(msg)
|
||||||
case *types.SearchDirectory:
|
case *types.SearchDirectory:
|
||||||
w.handleSearchDirectory(msg)
|
w.handleSearchDirectory(msg)
|
||||||
|
case *types.DirectoryInfoUpdateRequest:
|
||||||
|
// not implemented
|
||||||
default:
|
default:
|
||||||
reterr = errUnsupported
|
reterr = errUnsupported
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue