Skip to content

A platform for community discussion. Free, open, simple.

PERF: avoid left joins and distinct on posts_for query

Samd1684a165259
diff --git a/app/models/group.rb b/app/models/group.rb
index 7093e55327d..a3c467eb7bf 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -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)