FIX: don't try to feature a topic more than once per category

This commit is contained in:
Régis Hanol 2014-09-10 16:18:28 +02:00
parent dbcaf1276a
commit 8f45091ba5
1 changed files with 9 additions and 5 deletions

View File

@ -9,9 +9,8 @@ class CategoryFeaturedTopic < ActiveRecord::Base
CategoryFeaturedTopic.select(:topic_id, :category_id).order(:rank).each do |f|
(current[f.category_id] ||= []) << f.topic_id
end
Category.select(:id, :topic_id).all.each do |c|
feature_topics_for(c, current[c.id] || [])
Category.select(:id, :topic_id).find_each do |c|
CategoryFeaturedTopic.feature_topics_for(c, current[c.id] || [])
CategoryFeaturedUser.feature_users_in(c.id)
end
end
@ -20,8 +19,13 @@ class CategoryFeaturedTopic < ActiveRecord::Base
def self.feature_topics_for(c, existing=nil)
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)
results = query.list_category(c).topic_ids
query = TopicQuery.new(CategoryFeaturedTopic.fake_admin,
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