diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2018-11-14 08:07:35 +0300 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2018-12-10 23:34:33 +0300 |
commit | 4f5abe43279e96efde5f8cac66cbff30d8a95f28 (patch) | |
tree | 931664a9662da2de4ce46781d2715f6426afc120 /app | |
parent | 1297a1bd7dcccaa4e233925c8467c2bbe41a4bf2 (diff) |
Reduce N+1 from Activity Dashboard and Banzai
There is a combination of few strategies implemented here:
1. Few relations were eager loaded
2. Changed few polymorphic routes to specific ones so we don't have to
use `#becomes(Namespace)` which doesn't preserve association cache
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/events_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 2 | ||||
-rw-r--r-- | app/models/event.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 2 |
4 files changed, 7 insertions, 3 deletions
diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 3ce2398f1de..1371e9993b4 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -161,6 +161,10 @@ module EventsHelper project_commit_url(event.project, event.note_target, anchor: dom_id(event.target)) elsif event.project_snippet_note? project_snippet_url(event.project, event.note_target, anchor: dom_id(event.target)) + elsif event.issue_note? + project_issue_url(event.project, id: event.note_target, anchor: dom_id(event.target)) + elsif event.merge_request_note? + project_merge_request_url(event.project, id: event.note_target, anchor: dom_id(event.target)) else polymorphic_url([event.project.namespace.becomes(Namespace), event.project, event.note_target], diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 87aebe415c8..7c8557a1a8a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -2,7 +2,7 @@ module ProjectsHelper def link_to_project(project) - link_to [project.namespace.becomes(Namespace), project], title: h(project.name) do + link_to namespace_project_path(namespace_id: project.namespace, id: project), title: h(project.name) do title = content_tag(:span, project.name, class: 'project-name') if project.namespace diff --git a/app/models/event.rb b/app/models/event.rb index 2e690f8c013..2ceef412af5 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -87,7 +87,7 @@ class Event < ActiveRecord::Base scope :with_associations, -> do # 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) + includes(:author, :project, project: [:project_feature, :import_data, :namespace]) .preload(:target, :push_event_payload) end diff --git a/app/models/note.rb b/app/models/note.rb index a6ae4f58ac4..17c7d97fa0a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -131,7 +131,7 @@ class Note < ActiveRecord::Base scope :with_associations, -> do # FYI noteable cannot be loaded for LegacyDiffNote for commits includes(:author, :noteable, :updated_by, - project: [:project_members, { group: [:group_members] }]) + project: [:project_members, :namespace, { group: [:group_members] }]) end scope :with_metadata, -> { includes(:system_note_metadata) } |