Merge pull request #137 from cloudflare/silence-speedup

Don't iterate a dict, just grab the key
This commit is contained in:
Łukasz Mierzwa
2017-07-10 09:20:21 -07:00
committed by GitHub

View File

@@ -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