diff --git a/app/services/random_topic_selector.rb b/app/services/random_topic_selector.rb index d412a23890a..7486311cb6e 100644 --- a/app/services/random_topic_selector.rb +++ b/app/services/random_topic_selector.rb @@ -40,16 +40,18 @@ class RandomTopicSelector 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)