Don't write salts in initialization, look up on demand (#2702)

This commit is contained in:
Jeff Mitchell
2017-05-09 17:51:09 -04:00
committed by GitHub
parent 254ed1f744
commit eb0e7cd0d2
22 changed files with 248 additions and 239 deletions

View File

@@ -21,7 +21,7 @@ type PathMap struct {
Schema map[string]*FieldSchema
CaseSensitive bool
Salt *salt.Salt
SaltMutex *sync.RWMutex
SaltFunc func() (*salt.Salt, error)
once sync.Once
}
@@ -51,10 +51,12 @@ func (p *PathMap) pathStruct(k string) *PathStruct {
}
// If we have a salt, apply it before lookup
if p.Salt != nil {
p.SaltMutex.RLock()
k = p.Salt.SaltID(k)
p.SaltMutex.RUnlock()
salt := p.Salt
if p.SaltFunc != nil {
salt, _ = p.SaltFunc()
}
if salt != nil {
k = salt.SaltID(k)
}
return &PathStruct{