summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-03-26 10:07:17 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2018-03-26 10:07:17 +0000
commit545d52ce6ca1b296230b20cd2b219919ae38007b (patch)
tree2e3363f838231e1f8d2a424ecc03e25aecd863bf
parent0f85102d507394c44ca69fc0ef21d67e768d8c5f (diff)
parent783868e9faa1e3dff27765f8244dc59898a2f7b2 (diff)
downloadgitlab-ce-545d52ce6ca1b296230b20cd2b219919ae38007b.tar.gz
Merge branch 'ab-43150-users-controller-show-query-limit' into 'master'
Remove N+1 query for Noteable association. Closes #43150 See merge request gitlab-org/gitlab-ce!17956
-rw-r--r--app/models/event.rb10
-rw-r--r--changelogs/unreleased/ab-43150-users-controller-show-query-limit.yml5
2 files changed, 10 insertions, 5 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 17a198d52c7..3805f6cf857 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -52,12 +52,12 @@ class Event < ActiveRecord::Base
belongs_to :target, -> {
# If the association for "target" defines an "author" association we want to
# eager-load this so Banzai & friends don't end up performing N+1 queries to
- # get the authors of notes, issues, etc.
- if reflections['events'].active_record.reflect_on_association(:author)
- includes(:author)
- else
- self
+ # get the authors of notes, issues, etc. (likewise for "noteable").
+ incs = %i(author noteable).select do |a|
+ reflections['events'].active_record.reflect_on_association(a)
end
+
+ incs.reduce(self) { |obj, a| obj.includes(a) }
}, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
has_one :push_event_payload
diff --git a/changelogs/unreleased/ab-43150-users-controller-show-query-limit.yml b/changelogs/unreleased/ab-43150-users-controller-show-query-limit.yml
new file mode 100644
index 00000000000..502c1176d2d
--- /dev/null
+++ b/changelogs/unreleased/ab-43150-users-controller-show-query-limit.yml
@@ -0,0 +1,5 @@
+---
+title: Remove N+1 query for Noteable association.
+merge_request: 17956
+author:
+type: performance