FIX: invalid cache for parent category with limit_suggested_to_category

This commit is contained in:
Sam 2018-01-15 16:13:29 +11:00
parent 41a604a764
commit 38c018a84b
2 changed files with 15 additions and 6 deletions

View File

@ -6,9 +6,6 @@ class RandomTopicSelector
def 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)

View File

@ -43,6 +43,7 @@ class TopicQuery
page
per_page
visible
guardian
no_definitions)
end
@ -90,7 +91,7 @@ class TopicQuery
options.assert_valid_keys(TopicQuery.valid_options)
@options = options.dup
@user = user
@guardian = Guardian.new(@user)
@guardian = options[:guardian] || Guardian.new(@user)
end
def joined_topic_user(list = nil)