From 069e8cf1223b1ec4348f4d1a2fbca5235b2ab120 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 14 Apr 2015 20:57:42 +0900 Subject: [PATCH] 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. --- cmd/syncthing/summarysvc.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cmd/syncthing/summarysvc.go b/cmd/syncthing/summarysvc.go index 02f6c9fe..44ab7fc3 100644 --- a/cmd/syncthing/summarysvc.go +++ b/cmd/syncthing/summarysvc.go @@ -66,21 +66,25 @@ func (c *folderSummarySvc) listenForUpdates() { data := ev.Data.(map[string]interface{}) folder := data["folder"].(string) - if ev.Type == events.StateChanged && data["to"].(string) == "idle" && data["from"].(string) == "syncing" { - // The folder changed to idle from syncing. We should do an - // immediate refresh to update the GUI. The send to - // c.immediate must be nonblocking so that we can continue - // handling events. + switch ev.Type { + case events.StateChanged: + if data["to"].(string) == "idle" && data["from"].(string) == "syncing" { + // The folder changed to idle from syncing. We should do an + // immediate refresh to update the GUI. The send to + // c.immediate must be nonblocking so that we can continue + // handling events. - select { - case c.immediate <- folder: - c.foldersMut.Lock() - delete(c.folders, folder) - c.foldersMut.Unlock() + select { + case c.immediate <- folder: + c.foldersMut.Lock() + delete(c.folders, folder) + c.foldersMut.Unlock() - default: + default: + } } - } else { + + default: // This folder needs to be refreshed whenever we do the next // refresh.