Commit b011e9ad authored by Tan Le's avatar Tan Le

Improve project regulated settings check

More often we check for MR approval rules which invoke this method
multiple times. This change will cache the check result and avoid
unneeded trips to the database.
parent 76ddb27a
......@@ -216,10 +216,12 @@ module EE
end
def has_regulated_settings?
return unless compliance_framework_setting
strong_memoize(:has_regulated_settings) do
next false unless compliance_framework_setting
compliance_framework_id = ::ComplianceManagement::ComplianceFramework::FRAMEWORKS[compliance_framework_setting.framework.to_sym]
::Gitlab::CurrentSettings.current_application_settings.compliance_frameworks.include?(compliance_framework_id)
compliance_framework_id = ::ComplianceManagement::ComplianceFramework::FRAMEWORKS[compliance_framework_setting.framework.to_sym]
::Gitlab::CurrentSettings.current_application_settings.compliance_frameworks.include?(compliance_framework_id)
end
end
def can_store_security_reports?
......
---
title: Memoize project regulated settings check
merge_request: 37403
author:
type: performance
......@@ -573,9 +573,9 @@ RSpec.describe Project do
end
describe '#has_regulated_settings?' do
let_it_be(:framework) { ComplianceManagement::ComplianceFramework::FRAMEWORKS.first }
let_it_be(:compliance_framework_setting) { create(:compliance_framework_project_setting, framework: framework.first.to_s) }
let_it_be(:project) { create(:project, compliance_framework_setting: compliance_framework_setting) }
let(:framework) { ComplianceManagement::ComplianceFramework::FRAMEWORKS.first }
let(:compliance_framework_setting) { build(:compliance_framework_project_setting, framework: framework.first.to_s) }
let(:project) { build(:project, compliance_framework_setting: compliance_framework_setting) }
subject { project.has_regulated_settings? }
......@@ -596,7 +596,7 @@ RSpec.describe Project do
end
context 'project does not have compliance framework' do
let_it_be(:project) { create(:project) }
let(:project) { build(:project) }
it { is_expected.to be_falsey }
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