Don't schedule summaries on all state changes

Prior to this change we schedule summaries on each state change, i.e.
scanning->idle and idle->scanning, which is unnecessary. Now we only do
it on index updates, plus the immediate one on going syncing->idle.
This commit is contained in:
Jakob Borg 2015-04-14 20:57:42 +09:00
parent 45cbcaca6d
commit 069e8cf122

View File

@ -66,21 +66,25 @@ func (c *folderSummarySvc) listenForUpdates() {
data := ev.Data.(map[string]interface{}) data := ev.Data.(map[string]interface{})
folder := data["folder"].(string) folder := data["folder"].(string)
if ev.Type == events.StateChanged && data["to"].(string) == "idle" && data["from"].(string) == "syncing" { switch ev.Type {
// The folder changed to idle from syncing. We should do an case events.StateChanged:
// immediate refresh to update the GUI. The send to if data["to"].(string) == "idle" && data["from"].(string) == "syncing" {
// c.immediate must be nonblocking so that we can continue // The folder changed to idle from syncing. We should do an
// handling events. // immediate refresh to update the GUI. The send to
// c.immediate must be nonblocking so that we can continue
// handling events.
select { select {
case c.immediate <- folder: case c.immediate <- folder:
c.foldersMut.Lock() c.foldersMut.Lock()
delete(c.folders, folder) delete(c.folders, folder)
c.foldersMut.Unlock() c.foldersMut.Unlock()
default: default:
}
} }
} else {
default:
// This folder needs to be refreshed whenever we do the next // This folder needs to be refreshed whenever we do the next
// refresh. // refresh.