Commit 0a8fe94b authored by Alessio Caiazza's avatar Alessio Caiazza

Merge branch 'tancnle/memoize-project-regulated-settings-check' into 'master'

Memoize project regulated settings check

See merge request gitlab-org/gitlab!37403
parents 3e0b9c0f b011e9ad
...@@ -216,10 +216,12 @@ module EE ...@@ -216,10 +216,12 @@ module EE
end end
def has_regulated_settings? 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] compliance_framework_id = ::ComplianceManagement::ComplianceFramework::FRAMEWORKS[compliance_framework_setting.framework.to_sym]
::Gitlab::CurrentSettings.current_application_settings.compliance_frameworks.include?(compliance_framework_id) ::Gitlab::CurrentSettings.current_application_settings.compliance_frameworks.include?(compliance_framework_id)
end
end end
def can_store_security_reports? 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 ...@@ -573,9 +573,9 @@ RSpec.describe Project do
end end
describe '#has_regulated_settings?' do describe '#has_regulated_settings?' do
let_it_be(:framework) { ComplianceManagement::ComplianceFramework::FRAMEWORKS.first } let(:framework) { ComplianceManagement::ComplianceFramework::FRAMEWORKS.first }
let_it_be(:compliance_framework_setting) { create(:compliance_framework_project_setting, framework: framework.first.to_s) } let(:compliance_framework_setting) { build(:compliance_framework_project_setting, framework: framework.first.to_s) }
let_it_be(:project) { create(:project, compliance_framework_setting: compliance_framework_setting) } let(:project) { build(:project, compliance_framework_setting: compliance_framework_setting) }
subject { project.has_regulated_settings? } subject { project.has_regulated_settings? }
...@@ -596,7 +596,7 @@ RSpec.describe Project do ...@@ -596,7 +596,7 @@ RSpec.describe Project do
end end
context 'project does not have compliance framework' do context 'project does not have compliance framework' do
let_it_be(:project) { create(:project) } let(:project) { build(:project) }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
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