From 449455941ed1d0c05e5c067d148fd0c864c4e3a8 Mon Sep 17 00:00:00 2001 From: "micael.bergeron" Date: Mon, 11 Sep 2017 16:23:55 -0400 Subject: add association preloading for issue boards --- app/controllers/boards/issues_controller.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/controllers/boards/issues_controller.rb b/app/controllers/boards/issues_controller.rb index 8d4ec2d6d9d..1c33f9a69d8 100644 --- a/app/controllers/boards/issues_controller.rb +++ b/app/controllers/boards/issues_controller.rb @@ -11,9 +11,15 @@ module Boards issues = Boards::Issues::ListService.new(board_parent, current_user, filter_params).execute issues = issues.page(params[:page]).per(params[:per] || 20) make_sure_position_is_set(issues) + issues = issues.preload(:project, + :labels, + :milestone, + :assignees, + :notes => [:award_emoji, :author] + ) render json: { - issues: serialize_as_json(issues.preload(:project)), + issues: serialize_as_json(issues), size: issues.total_count } end @@ -76,14 +82,13 @@ module Boards def serialize_as_json(resource) resource.as_json( - labels: true, only: [:id, :iid, :project_id, :title, :confidential, :due_date, :relative_position], + labels: true, include: { project: { only: [:id, :path] }, assignees: { only: [:id, :name, :username], methods: [:avatar_url] }, milestone: { only: [:id, :title] } - }, - user: current_user + } ) end end -- cgit v1.2.1 From b376e5c80e3dc6f30dfcc06f6a63209381414f89 Mon Sep 17 00:00:00 2001 From: "micael.bergeron" Date: Tue, 12 Sep 2017 15:49:01 -0400 Subject: fix another N+1 query for label priorities added a QueryRecorder for IssuesController#index.json --- app/controllers/boards/issues_controller.rb | 4 ++-- app/models/label.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/controllers/boards/issues_controller.rb b/app/controllers/boards/issues_controller.rb index 1c33f9a69d8..0d74078645a 100644 --- a/app/controllers/boards/issues_controller.rb +++ b/app/controllers/boards/issues_controller.rb @@ -12,10 +12,10 @@ module Boards issues = issues.page(params[:page]).per(params[:per] || 20) make_sure_position_is_set(issues) issues = issues.preload(:project, - :labels, :milestone, :assignees, - :notes => [:award_emoji, :author] + labels: [:priorities], + notes: [:award_emoji, :author] ) render json: { diff --git a/app/models/label.rb b/app/models/label.rb index 958141a7358..899028a01a0 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -127,7 +127,12 @@ class Label < ActiveRecord::Base end def priority(project) - priorities.find_by(project: project).try(:priority) + priority = if priorities.loaded? + priorities.first { |p| p.project == project } + else + priorities.find_by(project: project) + end + priority.try(:priority) end def template? -- cgit v1.2.1