storage: add Benchmarks for ScrapeSwarm, optimize implementations

This commit is contained in:
Leo Balduf
2017-08-24 12:45:17 +02:00
parent d026424038
commit 5400a99b75
5 changed files with 48 additions and 6 deletions

View File

@@ -643,13 +643,14 @@ func (ps *peerStore) ScrapeSwarm(ih bittorrent.InfoHash, addressFamily bittorren
shard := ps.shards[ps.shardIndex(ih, addressFamily)]
shard.RLock()
if _, ok := shard.swarms[ih]; !ok {
swarm, ok := shard.swarms[ih]
if !ok {
shard.RUnlock()
return
}
resp.Incomplete = uint32(shard.swarms[ih].lenLeechers())
resp.Complete = uint32(shard.swarms[ih].lenSeeders())
resp.Incomplete = uint32(swarm.lenLeechers())
resp.Complete = uint32(swarm.lenSeeders())
shard.RUnlock()
return