PERF: avoid left joins and distinct on posts_for query
Previously this was extremely expensive due to the `distict` and `left join` clauses, this eliminates it and makes query much faster
This commit is contained in:
parent
e17a13ce19
commit
d1684a1652
|
@ -193,7 +193,8 @@ class Group < ActiveRecord::Base
|
|||
|
||||
def posts_for(guardian, opts = nil)
|
||||
opts ||= {}
|
||||
result = Post.includes(:topic, user: :groups, topic: :category)
|
||||
result = Post.joins(:topic, user: :groups, topic: :category)
|
||||
.preload(:topic, user: :groups, topic: :category)
|
||||
.references(:posts, :topics, :category)
|
||||
.where(groups: { id: id })
|
||||
.where('topics.archetype <> ?', Archetype.private_message)
|
||||
|
|
Loading…
Reference in New Issue