PERF: Remove N+1 query when generating posters summary.
This commit is contained in:
parent
f3fadf41b7
commit
195982fd41
|
@ -24,7 +24,9 @@ class PrimaryGroupLookup
|
|||
.select(:id, :primary_group_id)
|
||||
|
||||
group_lookup = {}
|
||||
group_ids = users_with_primary_group.map(&:primary_group_id).compact
|
||||
group_ids = users_with_primary_group.map(&:primary_group_id)
|
||||
group_ids.uniq!
|
||||
|
||||
Group.where(id: group_ids).select(self.class.lookup_columns)
|
||||
.each { |g| group_lookup[g.id] = g }
|
||||
|
||||
|
|
|
@ -346,8 +346,13 @@ class TopicQuery
|
|||
end
|
||||
|
||||
avatar_lookup = AvatarLookup.new(user_ids)
|
||||
primary_group_lookup = PrimaryGroupLookup.new(user_ids)
|
||||
|
||||
topics.each do |t|
|
||||
t.posters = t.posters_summary(avatar_lookup: avatar_lookup)
|
||||
t.posters = t.posters_summary(
|
||||
avatar_lookup: avatar_lookup,
|
||||
primary_group_lookup: primary_group_lookup
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue