PERF: no need to nest a transaction when featuring topics

adding featured topics is already in a transaction, no need to nest
This commit is contained in:
Sam Saffron 2016-07-16 15:36:40 +10:00
parent 4cef1c1750
commit 9893953f62
1 changed files with 6 additions and 8 deletions

View File

@ -4,14 +4,12 @@ class CategoryFeaturedTopic < ActiveRecord::Base
# Populates the category featured topics
def self.feature_topics
transaction do
current = {}
CategoryFeaturedTopic.select(:topic_id, :category_id).order(:rank).each do |f|
(current[f.category_id] ||= []) << f.topic_id
end
Category.select(:id, :topic_id).find_each do |c|
CategoryFeaturedTopic.feature_topics_for(c, current[c.id] || [])
end
current = {}
CategoryFeaturedTopic.select(:topic_id, :category_id).order(:rank).each do |f|
(current[f.category_id] ||= []) << f.topic_id
end
Category.select(:id, :topic_id).find_each do |c|
CategoryFeaturedTopic.feature_topics_for(c, current[c.id] || [])
end
end