Permalink
Browse files

PERF: instead of N redis operations perform in bulk

  • Loading branch information...
SamSaffron committed Oct 2, 2015
1 parent 4334506 commit 1754fcccf75983c642497b78a6d8c2b3edb08964
Showing with 9 additions and 7 deletions.
  1. +9 −7 app/services/random_topic_selector.rb
@@ -40,16 +40,18 @@ def self.next(count, category=nil)

results = []

left = count
return results if count < 1

while left > 0
id = $redis.lpop key
break unless id

results << id.to_i
left -= 1
results = $redis.multi do
$redis.lrange(key, 0, count-1)
$redis.ltrim(key, count, -1)
end

results = results[0]
results.map!(&:to_i)

left = count - results.length

backfilled = false
if left > 0
ids = backfill(category)

0 comments on commit 1754fcc

Please sign in to comment.