tpl/partials: Fix the lock contention in cached partial

Fixes #4086
This commit is contained in:
Bjørn Erik Pedersen 2017-11-16 11:59:45 +01:00
parent e66d813bcb
commit 6233ddf9d1
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -120,19 +120,17 @@ func (ns *Namespace) getOrCreate(key, name string, context interface{}) (interfa
return p, nil return p, nil
} }
ns.cachedPartials.Lock()
defer ns.cachedPartials.Unlock()
// Double-check.
if p, ok = ns.cachedPartials.p[key]; ok {
return p, nil
}
p, err := ns.Include(name, context) p, err := ns.Include(name, context)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ns.cachedPartials.Lock()
defer ns.cachedPartials.Unlock()
// Double-check.
if p2, ok := ns.cachedPartials.p[key]; ok {
return p2, nil
}
ns.cachedPartials.p[key] = p ns.cachedPartials.p[key] = p
return p, nil return p, nil