diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-12-07 14:51:45 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-12-08 12:33:51 +0100 |
commit | c52a36e85959a5461b74bae8f881043a4e4feb45 (patch) | |
tree | 2001569f9df252a9277b31d609bb255b010fe874 /app/models/event.rb | |
parent | 9429e8ac60a10436a0469d7d206d3f74a2c966c7 (diff) | |
download | gitlab-ce-c52a36e85959a5461b74bae8f881043a4e4feb45.tar.gz |
Fix N+1 query when displaying eventsfix-event-target-author-preloading
When displaying events we would load the target of those events, then
render the entire data using our Markdown pipeline. This pipeline would
eventually request the author of every target, leading to an additional
query being executed for every target to get the author.
To fix this we now eager load the author of the event's target. In my
local environment this reduces the number of queries to display a
project's Atom feed from 40 to 24 queries.
See https://gitlab.com/gitlab-org/gitlab-ce/issues/36878 for more
information.
Diffstat (limited to 'app/models/event.rb')
-rw-r--r-- | app/models/event.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index 0997b056c6a..6053594fab5 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -72,7 +72,7 @@ class Event < ActiveRecord::Base # We're using preload for "push_event_payload" as otherwise the association # is not always available (depending on the query being built). includes(:author, :project, project: :namespace) - .preload(:target, :push_event_payload) + .preload(:push_event_payload, target: :author) end scope :for_milestone_id, ->(milestone_id) { where(target_type: "Milestone", target_id: milestone_id) } |