A platform for community discussion. Free, open, simple.
FIX: invalid cache for parent category with limit_suggested_to_category
Sam38c018a84bf4
diff --git a/app/services/random_topic_selector.rb b/app/services/random_topic_selector.rbindex 4aaa7d3343f..1ac2d8500a9 100644--- a/app/services/random_topic_selector.rb+++ b/app/services/random_topic_selector.rb@@ -6,9 +6,6 @@ class RandomTopicSelectordef self.backfill(category = nil)exclude = category&.topic_id- # don't leak private categories into the "everything" group- user = category ? CategoryFeaturedTopic.fake_admin : nil-options = {per_page: category ? category.num_featured_topics : 3,visible: true,@@ -16,9 +13,20 @@ class RandomTopicSelector}options[:except_topic_ids] = [category.topic_id] if exclude- options[:category] = category.id if category- query = TopicQuery.new(user, options)+ if category+ options[:category] = category.id+ # NOTE: at the moment this site setting scopes tightly to a category (excluding subcats)+ # this is done so we don't populate a junk cache+ if SiteSetting.limit_suggested_to_category+ options[:no_subcategories] = true+ end++ # don't leak private categories into the "everything" group+ options[:guardian] = Guardian.new(CategoryFeaturedTopic.fake_admin)+ end++ query = TopicQuery.new(nil, options)results = query.latest_results.order('RANDOM()').where(closed: false, archived: false)diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex 572f19be085..3dae7132e09 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -43,6 +43,7 @@ class TopicQuerypageper_pagevisible+ guardianno_definitions)end@@ -90,7 +91,7 @@ class TopicQueryoptions.assert_valid_keys(TopicQuery.valid_options)@options = options.dup@user = user- @guardian = Guardian.new(@user)+ @guardian = options[:guardian] || Guardian.new(@user)enddef joined_topic_user(list = nil)