summaryrefslogtreecommitdiff
path: root/app/models/discussion.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-05-29 16:07:57 -0500
committerDouwe Maan <douwe@selenight.nl>2017-05-29 16:08:05 -0500
commite53169c9702f1f4f25f8f1e91ed9ab7ace0a3d41 (patch)
tree6a051e9da6794f0fc70fcf0dca018236dfb3dc30 /app/models/discussion.rb
parent1ac12698c613774bdace72475573916c142a07e4 (diff)
downloadgitlab-ce-e53169c9702f1f4f25f8f1e91ed9ab7ace0a3d41.tar.gz
Resolve N+1 query issue with discussions
Diffstat (limited to 'app/models/discussion.rb')
-rw-r--r--app/models/discussion.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 0b6b920ed66..6a92b8eef66 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -21,7 +21,8 @@ class Discussion
end
def self.build_collection(notes, context_noteable = nil)
- notes.group_by { |n| n.discussion_id(context_noteable) }.values.map { |notes| build(notes, context_noteable) }
+ grouped_notes = notes.includes(:noteable).group_by { |n| n.discussion_id(context_noteable) }
+ grouped_notes.values.map { |notes| build(notes, context_noteable) }
end
# Returns an alphanumeric discussion ID based on `build_discussion_id`