Skip to content
Snippets Groups Projects
Commit 1554786c authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Eager load various issue/note associations

This ensures we don't end up running N+1 queries for the objects in the
affected collections.
parent ff8f7fb0
No related branches found
No related tags found
1 merge request!1578Performance improvements when viewing individual issues
Loading
Loading
@@ -57,7 +57,7 @@ class Projects::IssuesController < Projects::ApplicationController
def show
@participants = @issue.participants(current_user)
@note = @project.notes.new(noteable: @issue)
@notes = @issue.notes.inc_author.fresh
@notes = @issue.notes.inc_associations.fresh
@noteable = @issue
 
respond_with(@issue)
Loading
Loading
Loading
Loading
@@ -47,7 +47,8 @@ module Issuable
prefix: true
 
attr_mentionable :title, :description
participant :author, :assignee, :notes, :mentioned_users
participant :author, :assignee, :notes_with_associations, :mentioned_users
end
 
module ClassMethods
Loading
Loading
@@ -176,6 +177,10 @@ module Issuable
self.class.to_s.underscore
end
 
def notes_with_associations
notes.includes(:author, :project)
end
private
 
def filter_superceded_votes(votes, notes)
Loading
Loading
Loading
Loading
@@ -64,7 +64,7 @@ class Group < Namespace
end
 
def owners
@owners ||= group_members.owners.map(&:user)
@owners ||= group_members.owners.includes(:user).map(&:user)
end
 
def add_users(user_ids, access_level, current_user = nil)
Loading
Loading
Loading
Loading
@@ -59,6 +59,7 @@ class Note < ActiveRecord::Base
scope :fresh, ->{ order(created_at: :asc, id: :asc) }
scope :inc_author_project, ->{ includes(:project, :author) }
scope :inc_author, ->{ includes(:author) }
scope :inc_associations, ->{ includes(:author, :noteable, :updated_by) }
 
serialize :st_diff
before_create :set_diff, if: ->(n) { n.line_code.present? }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment