Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-06-01 12:01:08 +0300
committerSean McGivern <sean@mcgivern.me.uk>2017-06-01 12:01:08 +0300
commit69e31003beee21d9532bdbad979528a48c230679 (patch)
tree73063027af9a1875b4d64fe09803220c7322453e /app
parentdd0f8b8ccc3b5f61e31703f7391a919b702934a5 (diff)
parent78207b95ca7795c82bfc14fdf35422714906b14d (diff)
Merge branch 'dm-discussions-n-plus-1' into 'master'
Resolve N+1 query issue with discussions Closes #33013 See merge request !11775
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/noteable.rb7
-rw-r--r--app/models/discussion.rb3
-rw-r--r--app/models/note.rb2
3 files changed, 9 insertions, 3 deletions
diff --git a/app/models/concerns/noteable.rb b/app/models/concerns/noteable.rb
index dd1e6630642..c7bdc997eca 100644
--- a/app/models/concerns/noteable.rb
+++ b/app/models/concerns/noteable.rb
@@ -43,7 +43,12 @@ module Noteable
end
def resolvable_discussions
- @resolvable_discussions ||= discussion_notes.resolvable.discussions(self)
+ @resolvable_discussions ||=
+ if defined?(@discussions)
+ @discussions.select(&:resolvable?)
+ else
+ discussion_notes.resolvable.discussions(self)
+ end
end
def discussions_resolvable?
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 0b6b920ed66..9b32d573387 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.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`
diff --git a/app/models/note.rb b/app/models/note.rb
index 60257aac93b..832c68243fb 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -110,7 +110,7 @@ class Note < ActiveRecord::Base
end
def discussions(context_noteable = nil)
- Discussion.build_collection(fresh, context_noteable)
+ Discussion.build_collection(all.includes(:noteable).fresh, context_noteable)
end
def find_discussion(discussion_id)