FIX: Improve performance for `Group.posts_for` (#6588)

This commit is contained in:
David Taylor 2018-11-12 00:44:20 +00:00 committed by Guo Xiang Tan
parent cee1f5b2c1
commit c3c9299c44
1 changed files with 2 additions and 3 deletions

View File

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