summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-01-04 16:46:40 +0000
committerDouwe Maan <douwe@gitlab.com>2018-01-04 16:46:40 +0000
commitd83c4049de46b44c2ac8140345d74fb8f0487370 (patch)
treecf921f107a7c677535bf1f52dfec7ee9c7b6b7d4 /app/models
parent7d3e6d09021b677c4765a58540d1278bc3948322 (diff)
parentdac51ace521d7b2b2a5a5bb19167a8690ead242e (diff)
downloadgitlab-ce-d83c4049de46b44c2ac8140345d74fb8f0487370.tar.gz
Merge branch 'conditionally-eager-load-event-target-authors' into 'master'
Eager load event target authors whenever possible Closes #41618 See merge request gitlab-org/gitlab-ce!16199
Diffstat (limited to 'app/models')
-rw-r--r--app/models/event.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 0997b056c6a..8a79100de5a 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -48,7 +48,18 @@ class Event < ActiveRecord::Base
belongs_to :author, class_name: "User"
belongs_to :project
- belongs_to :target, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
+
+ 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
+ end
+ }, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
+
has_one :push_event_payload
# Callbacks