From ee52a00a266aa41847c54a487a46bad993155aa8 Mon Sep 17 00:00:00 2001 From: Justin Kolberg Date: Tue, 5 Jun 2018 13:08:27 -0700 Subject: [PATCH] add concurrency to buildClients() Signed-off-by: Justin Kolberg --- uchiwa/daemon/clients.go | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/uchiwa/daemon/clients.go b/uchiwa/daemon/clients.go index 18576c5..69ba07c 100644 --- a/uchiwa/daemon/clients.go +++ b/uchiwa/daemon/clients.go @@ -2,6 +2,7 @@ package daemon import ( "fmt" + "sync" "github.com/mitchellh/mapstructure" "github.com/sensu/uchiwa/uchiwa/helpers" @@ -11,28 +12,38 @@ import ( // buildClients constructs clients objects for frontend consumption func (d *Daemon) buildClients() { + wg := &sync.WaitGroup{} + for _, c := range d.Data.Clients { - client, ok := c.(map[string]interface{}) - if !ok { - continue - } + wg.Add(1) - dc, ok := client["dc"].(string) - if !ok { - continue - } + go d.buildClient(c, wg) + } - name, ok := client["name"].(string) - if !ok { - continue - } + wg.Wait() +} - client["_id"] = fmt.Sprintf("%s/%s", dc, name) +func (d *Daemon) buildClient(c interface{}, wg *sync.WaitGroup) { + defer wg.Done() - client = findClientEvents(client, &d.Data.Events) + client, ok := c.(map[string]interface{}) + if !ok { + return + } - client["silenced"] = helpers.IsClientSilenced(name, dc, d.Data.Silenced) + dc, ok := client["dc"].(string) + if !ok { + return } + + name, ok := client["name"].(string) + if !ok { + return + } + + client["_id"] = fmt.Sprintf("%s/%s", dc, name) + client = findClientEvents(client, &d.Data.Events) + client["silenced"] = helpers.IsClientSilenced(name, dc, d.Data.Silenced) } // findClientEvents searches for all events related to a particular client