FIX: Improve performance for `Group.posts_for` (#6588)
This commit is contained in:
parent
cee1f5b2c1
commit
c3c9299c44
|
@ -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])
|
||||||
|
|
Loading…
Reference in New Issue