Commit af9511b6 authored by Markus Koller's avatar Markus Koller

Merge branch 'cablett-board-list-efficiency' into 'master'

Prevent N+1 in board list issue service via strong memoize

See merge request gitlab-org/gitlab!38050
parents 4504c75b 63bd331f
...@@ -55,9 +55,17 @@ module Boards ...@@ -55,9 +55,17 @@ module Boards
end end
def list def list
return @list if defined?(@list) return unless params.key?(:id)
@list = board.lists.find(params[:id]) if params.key?(:id) strong_memoize(:list) do
id = params[:id]
if board.lists.loaded?
board.lists.find { |l| l.id == id }
else
board.lists.find(id)
end
end
end end
def filter_params def filter_params
......
...@@ -19,6 +19,15 @@ RSpec.shared_examples 'issues list service' do ...@@ -19,6 +19,15 @@ RSpec.shared_examples 'issues list service' do
end end
end end
it 'avoids N+1' do
params = { board_id: board.id }
control = ActiveRecord::QueryRecorder.new { described_class.new(parent, user, params).execute }
create(:list, board: board)
expect { described_class.new(parent, user, params).execute }.not_to exceed_query_limit(control)
end
context 'issues are ordered by priority' do context 'issues are ordered by priority' do
it 'returns opened issues when list_id is missing' do it 'returns opened issues when list_id is missing' do
params = { board_id: board.id } params = { board_id: board.id }
......
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