Commit 63bd331f authored by charlie ablett's avatar charlie ablett

Strongly memoize list

- Add N+1 test
parent 25a98527
......@@ -55,9 +55,17 @@ module Boards
end
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
def filter_params
......
......@@ -19,6 +19,15 @@ RSpec.shared_examples 'issues list service' do
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
it 'returns opened issues when list_id is missing' do
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