Remove subtransactions from Vulnerabilities::HistoricalStatistic
One item was identified as a short term opportunity to alleviate subtransactions' impact to GitLab.com availability in &6540 (comment 648749714)
The most common use of subtransactions appears to be this pattern:
SomeActiveRecordModel.safe_ensure_unique(retries: 1) do
record = SomeActiveRecordModel.find_or_initialize_by(some_attributes)
<do stuff to record>
For example:
project = Project.first
ApplicationRecord.transaction do
::Vulnerabilities::HistoricalStatistic.safe_ensure_unique(retries: 1) do
project.vulnerability_historical_statistics.find_or_initialize_by(date: Time.now)
end
end
This effectively translates to:
BEGIN
SAVEPOINT
SELECT * FROM vulnerability_historical_statistics WHERE xxx LIMIT 1
RELEASE SAVEPOINT
COMMIT
Edited by Chun Du