diff --git a/app/services/random_topic_selector.rb b/app/services/random_topic_selector.rb index ac4945afe1c..8ce962f760b 100644 --- a/app/services/random_topic_selector.rb +++ b/app/services/random_topic_selector.rb @@ -68,6 +68,12 @@ class RandomTopicSelector results end + def self.clear_cache! + Category.select(:id).each do |c| + $redis.del cache_key(c) + end + end + def self.cache_key(category=nil) "random_topic_cache_#{category.try(:id)}" end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index c4223114e96..a1f9bd3adc3 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -406,7 +406,7 @@ describe TopicQuery do before do - $redis.del RandomTopicSelector.cache_key + RandomTopicSelector.clear_cache! end context 'when anonymous' do @@ -463,12 +463,12 @@ describe TopicQuery do end it "won't return new or fully read if there are enough partially read topics" do - SiteSetting.stubs(:suggested_topics).returns(1) + SiteSetting.suggested_topics = 1 expect(suggested_topics).to eq([partially_read.id]) end it "won't return fully read if there are enough partially read topics and new topics" do - SiteSetting.stubs(:suggested_topics).returns(4) + SiteSetting.suggested_topics = 4 expect(suggested_topics[0]).to eq(partially_read.id) expect(suggested_topics[1,3]).to include(new_topic.id) expect(suggested_topics[1,3]).to include(closed_topic.id) @@ -476,7 +476,7 @@ describe TopicQuery do end it "returns unread, then new, then random" do - SiteSetting.stubs(:suggested_topics).returns(7) + SiteSetting.suggested_topics = 7 expect(suggested_topics[0]).to eq(partially_read.id) expect(suggested_topics[1,3]).to include(new_topic.id) expect(suggested_topics[1,3]).to include(closed_topic.id)