From fb75e6b083875519dcdc12e42843dd01078ce8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 8 Jul 2017 14:20:08 -0700 Subject: [PATCH] Don't iterate a dict, just grab the key This is slow, it's a dict, not need to iterate that. --- alertmanager/models.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/alertmanager/models.go b/alertmanager/models.go index 546c639bf..4455a86c6 100644 --- a/alertmanager/models.go +++ b/alertmanager/models.go @@ -254,13 +254,11 @@ func (am *Alertmanager) SilenceByID(id string) (models.Silence, error) { am.lock.RLock() defer am.lock.RUnlock() - for k, v := range am.silences { - if k == id { - return models.Silence(v), nil - } + s, found := am.silences[id] + if !found { + return models.Silence{}, fmt.Errorf("Silence '%s' not found", id) } - - return models.Silence{}, fmt.Errorf("Silence '%s' not found", id) + return s, nil } // Colors returns a copy of all color maps