Commit 73a32a6d authored by Andy Soiron's avatar Andy Soiron

Merge branch 'sk/338085-move-statistics-out-of-txn' into 'master'

Move vulnerability statistics update out of transaction

See merge request gitlab-org/gitlab!69045
parents 331e9287 8de7a2fb
......@@ -18,13 +18,16 @@ module Vulnerabilities
Vulnerabilities::Finding.transaction(requires_new: true) do # rubocop:disable Performance/ActiveRecordSubtransactions
save_vulnerability(vulnerability, finding)
Statistics::UpdateService.update_for(vulnerability)
HistoricalStatistics::UpdateService.update_for(@project)
rescue ActiveRecord::RecordNotFound
vulnerability.errors.add(:base, _('finding is not found or is already attached to a vulnerability'))
raise ActiveRecord::Rollback
end
if vulnerability.persisted?
Statistics::UpdateService.update_for(vulnerability)
HistoricalStatistics::UpdateService.update_for(@project)
end
vulnerability
end
......
......@@ -93,6 +93,13 @@ RSpec.describe Vulnerabilities::CreateService do
it 'rejects creation of a new vulnerability from this finding' do
expect(subject.errors.messages).to eq(expected_error_messages)
end
it 'does not update vulnerability statistics' do
subject
expect(Vulnerabilities::HistoricalStatistics::UpdateService).not_to receive(:update_for)
expect(Vulnerabilities::Statistics::UpdateService).not_to receive(:update_for)
end
end
context 'when security dashboard feature is disabled' do
......
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