Commit 6b80dc05 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-slow-test-case-with-large-sql-query' into 'master'

Fix slow reference parser test case

See merge request gitlab-org/gitlab!47365
parents 4914291c 50dc6150
......@@ -178,7 +178,10 @@ module Banzai
collection.where(id: to_query).each { |row| cache[row.id] = row }
end
ids.uniq.map { |id| cache[id] }.compact
ids.each_with_object([]) do |id, array|
row = cache[id]
array << row if row
end
else
collection.where(id: ids)
end
......
......@@ -323,6 +323,9 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do
it 'will not overflow the stack' do
ids = 1.upto(1_000_000).to_a
# Avoid executing a large, unnecessary SQL query
expect(User).to receive(:where).with(id: ids).and_return(User.none)
expect { subject.collection_objects_for_ids(User, ids) }.not_to raise_error
end
end
......
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