Commit 54985c7a authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'mk/fix-issue-board-query-dupe' into 'master'

Fix duplicate query problem in `boards/issues`

See merge request gitlab-org/gitlab!27505
parents db6a6603 b539ba50
......@@ -24,17 +24,14 @@ module Boards
push_frontend_feature_flag(:board_search_optimization, board.group)
end
# rubocop: disable CodeReuse/ActiveRecord
def index
list_service = Boards::Issues::ListService.new(board_parent, current_user, filter_params)
issues = list_service.execute
issues = issues.page(params[:page]).per(params[:per] || 20).without_count
issues = issues_from(list_service)
Issue.move_nulls_to_end(issues) if Gitlab::Database.read_write?
issues = issues.preload(associations_to_preload)
render_issues(issues, list_service.metadata)
end
# rubocop: enable CodeReuse/ActiveRecord
def create
service = Boards::Issues::CreateService.new(board_parent, project, current_user, issue_params)
......@@ -67,6 +64,14 @@ module Boards
private
def issues_from(list_service)
issues = list_service.execute
issues.page(params[:page]).per(params[:per] || 20)
.without_count
.preload(associations_to_preload) # rubocop: disable CodeReuse/ActiveRecord
.load
end
def associations_to_preload
[
:milestone,
......
---
title: Fix redundant query execution when loading board issues
merge_request: 27505
author:
type: performance
......@@ -112,6 +112,13 @@ describe Boards::IssuesController do
expect { list_issues(user: user, board: group_board, list: list3) }.not_to exceed_query_limit(control_count + (2 * 8 - 1))
end
it 'does not query issues table more than once' do
recorder = ActiveRecord::QueryRecorder.new { list_issues(user: user, board: board, list: list1) }
query_count = recorder.occurrences.select { |query,| query.start_with?('SELECT issues.*') }.each_value.first
expect(query_count).to eq(1)
end
end
context 'with invalid list id' do
......
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