Skip to content
代码片段 群组 项目
未验证 提交 8129bf94 编辑于 作者: Gregory Havenga's avatar Gregory Havenga 提交者: GitLab
浏览文件

Only load vulnerability related records when actually exporting

Without this change, the `with_findings_scanner_identifiers_and_notes`
scope eager loads all the supporting models for the serialisation when
we are enqueing the export and will not use this data. This also occurs
before the inner `enumerator` is used, meaning the batch size is too
large to actually carry out.

Changelog: fixed
EE: true
上级 23e8b72b
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
......@@ -179,7 +179,6 @@ def vulnerability_reads_scope
exportable.vulnerability_reads.unarchived.order_traversal_ids_asc
else
Security::VulnerabilityReadsFinder.new(exportable).execute
.with_findings_scanner_identifiers_and_notes
.order_detected_at_asc
end
end
......
......@@ -36,6 +36,14 @@
expect(csv['Vulnerability']).to match_array(expected_titles)
expect(csv['Status']).to match_array(expected_states)
end
it 'does not have an N+1' do
query_count = ActiveRecord::QueryRecorder.new do
export_segment
end.count
expect(query_count).to eq(expected_export_query_count)
end
end
describe '#export_segment' do
......@@ -65,6 +73,7 @@
context 'when exporting a group' do
let(:expected_titles) { [vulnerability_1.title, vulnerability_2.title, vulnerability_3.title] }
let(:expected_states) { [vulnerability_1.state, vulnerability_2.state, vulnerability_3.state] }
let(:expected_export_query_count) { 21 }
it_behaves_like 'generates an exported segment'
end
......@@ -82,6 +91,7 @@
let(:expected_titles) { [vulnerability_2.title, vulnerability_3.title] }
let(:expected_states) { [vulnerability_2.state, vulnerability_3.state] }
let(:expected_export_query_count) { 21 }
it_behaves_like 'generates an exported segment'
end
......@@ -255,6 +265,14 @@
export
end
it 'does not attempt to preload the export data unnecessarily' do
query_count = ActiveRecord::QueryRecorder.new do
export
end.count
expect(query_count).to eq(12)
end
it 'sets organization_id appropriately' do
expect { export }.to change { ::Vulnerabilities::Export::Part.count }.from(0).to(2)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册