Commit 62052283 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '119333-systemstackerror-stack-level-too-deep' into 'master'

Prevent stack overflowing with a lot of user references

Closes #119333

See merge request gitlab-org/gitlab!22247
parents c3fa73f9 e8faadae
...@@ -177,7 +177,7 @@ module Banzai ...@@ -177,7 +177,7 @@ module Banzai
collection.where(id: to_query).each { |row| cache[row.id] = row } collection.where(id: to_query).each { |row| cache[row.id] = row }
end end
cache.values_at(*ids).compact ids.uniq.map { |id| cache[id] }.compact
else else
collection.where(id: ids) collection.where(id: ids)
end end
......
...@@ -312,6 +312,12 @@ describe Banzai::ReferenceParser::BaseParser do ...@@ -312,6 +312,12 @@ describe Banzai::ReferenceParser::BaseParser do
expect(subject.collection_objects_for_ids(Project, [project.id])) expect(subject.collection_objects_for_ids(Project, [project.id]))
.to eq([project]) .to eq([project])
end end
it 'will not overflow the stack' do
ids = 1.upto(1_000_000).to_a
expect { subject.collection_objects_for_ids(User, ids) }.not_to raise_error
end
end end
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