Remove n+1 query on Categories

This commit is contained in:
cpradio 2014-11-17 15:43:22 -05:00
parent ce78cb1ee4
commit cca78f1031
1 changed files with 1 additions and 1 deletions

View File

@ -38,7 +38,7 @@ class Group < ActiveRecord::Base
def posts_for(guardian, before_post_id=nil) def posts_for(guardian, before_post_id=nil)
user_ids = group_users.map {|gu| gu.user_id} user_ids = group_users.map {|gu| gu.user_id}
result = Post.where(user_id: user_ids).includes(:user, :topic).references(:posts, :topics) result = Post.where(user_id: user_ids).includes(:user, :topic, :topic => :category).references(:posts, :topics, :category)
.where('topics.archetype <> ?', Archetype.private_message) .where('topics.archetype <> ?', Archetype.private_message)
.where(post_type: Post.types[:regular]) .where(post_type: Post.types[:regular])