FIX: Topic view not working when Redis is readonly.
This commit is contained in:
parent
5f4075a6cf
commit
5f8e20aa1d
|
@ -47,7 +47,12 @@ class RandomTopicSelector
|
||||||
$redis.ltrim(key, count, -1)
|
$redis.ltrim(key, count, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
results = results[0]
|
if !results.is_a?(Array) # Redis is in readonly mode
|
||||||
|
results = $redis.lrange(key, 0, count-1)
|
||||||
|
else
|
||||||
|
results = results[0]
|
||||||
|
end
|
||||||
|
|
||||||
results.map!(&:to_i)
|
results.map!(&:to_i)
|
||||||
|
|
||||||
left = count - results.length
|
left = count - results.length
|
||||||
|
|
|
@ -11,8 +11,15 @@ describe RandomTopicSelector do
|
||||||
$redis.rpush key, t
|
$redis.rpush key, t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expect(RandomTopicSelector.next(0)).to eq([])
|
||||||
expect(RandomTopicSelector.next(2)).to eq([0,1])
|
expect(RandomTopicSelector.next(2)).to eq([0,1])
|
||||||
|
|
||||||
|
$redis.expects(:multi).returns(Discourse.received_readonly!)
|
||||||
expect(RandomTopicSelector.next(2)).to eq([2,3])
|
expect(RandomTopicSelector.next(2)).to eq([2,3])
|
||||||
|
$redis.unstub(:multi)
|
||||||
|
|
||||||
|
expect(RandomTopicSelector.next(2)).to eq([2,3])
|
||||||
|
expect(RandomTopicSelector.next(2)).to eq([])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can correctly backfill' do
|
it 'can correctly backfill' do
|
||||||
|
|
Loading…
Reference in New Issue