mirror of
https://github.com/discourse/discourse.git
synced 2025-03-31 06:06:00 +08:00
FIX: don't try to feature a topic more than once per category
This commit is contained in:
parent
dbcaf1276a
commit
8f45091ba5
@ -9,9 +9,8 @@ class CategoryFeaturedTopic < ActiveRecord::Base
|
|||||||
CategoryFeaturedTopic.select(:topic_id, :category_id).order(:rank).each do |f|
|
CategoryFeaturedTopic.select(:topic_id, :category_id).order(:rank).each do |f|
|
||||||
(current[f.category_id] ||= []) << f.topic_id
|
(current[f.category_id] ||= []) << f.topic_id
|
||||||
end
|
end
|
||||||
Category.select(:id, :topic_id).all.each do |c|
|
Category.select(:id, :topic_id).find_each do |c|
|
||||||
|
CategoryFeaturedTopic.feature_topics_for(c, current[c.id] || [])
|
||||||
feature_topics_for(c, current[c.id] || [])
|
|
||||||
CategoryFeaturedUser.feature_users_in(c.id)
|
CategoryFeaturedUser.feature_users_in(c.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -20,8 +19,13 @@ class CategoryFeaturedTopic < ActiveRecord::Base
|
|||||||
def self.feature_topics_for(c, existing=nil)
|
def self.feature_topics_for(c, existing=nil)
|
||||||
return if c.blank?
|
return if c.blank?
|
||||||
|
|
||||||
query = TopicQuery.new(self.fake_admin, per_page: SiteSetting.category_featured_topics, except_topic_ids: [c.topic_id], visible: true, no_definitions: true)
|
query = TopicQuery.new(CategoryFeaturedTopic.fake_admin,
|
||||||
results = query.list_category(c).topic_ids
|
per_page: SiteSetting.category_featured_topics,
|
||||||
|
except_topic_ids: [c.topic_id],
|
||||||
|
visible: true,
|
||||||
|
no_definitions: true)
|
||||||
|
|
||||||
|
results = query.list_category(c).topic_ids.uniq
|
||||||
|
|
||||||
return if results == existing
|
return if results == existing
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user