PERF: instead of N redis operations perform in bulk
This commit is contained in:
parent
43345063b9
commit
1754fcccf7
|
@ -40,16 +40,18 @@ class RandomTopicSelector
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
left = count
|
return results if count < 1
|
||||||
|
|
||||||
while left > 0
|
results = $redis.multi do
|
||||||
id = $redis.lpop key
|
$redis.lrange(key, 0, count-1)
|
||||||
break unless id
|
$redis.ltrim(key, count, -1)
|
||||||
|
|
||||||
results << id.to_i
|
|
||||||
left -= 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
results = results[0]
|
||||||
|
results.map!(&:to_i)
|
||||||
|
|
||||||
|
left = count - results.length
|
||||||
|
|
||||||
backfilled = false
|
backfilled = false
|
||||||
if left > 0
|
if left > 0
|
||||||
ids = backfill(category)
|
ids = backfill(category)
|
||||||
|
|
Loading…
Reference in New Issue