Commit 545d52ce authored by Yorick Peterse's avatar Yorick Peterse

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
parents 0f85102d 783868e9
......@@ -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
......
---
title: Remove N+1 query for Noteable association.
merge_request: 17956
author:
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment