[#1157] network/cache: Optimize client
fetch from multiClient
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
a4261243fc
commit
2a69aaf976
1 changed files with 11 additions and 6 deletions
17
pkg/network/cache/multi.go
vendored
17
pkg/network/cache/multi.go
vendored
|
@ -235,16 +235,21 @@ func (x *multiClient) RawForAddress(addr network.Address, f func(client *rawclie
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *multiClient) client(addr network.Address) clientcore.Client {
|
func (x *multiClient) client(addr network.Address) clientcore.Client {
|
||||||
x.mtx.Lock()
|
|
||||||
|
|
||||||
strAddr := addr.String()
|
strAddr := addr.String()
|
||||||
|
|
||||||
|
x.mtx.RLock()
|
||||||
c, cached := x.clients[strAddr]
|
c, cached := x.clients[strAddr]
|
||||||
if !cached {
|
x.mtx.RUnlock()
|
||||||
c = x.createForAddress(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
x.mtx.Unlock()
|
if !cached {
|
||||||
|
x.mtx.Lock()
|
||||||
|
|
||||||
|
c, cached = x.clients[strAddr]
|
||||||
|
if !cached {
|
||||||
|
c = x.createForAddress(addr)
|
||||||
|
}
|
||||||
|
x.mtx.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue