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,11 +216,13 @@ module EE ...@@ -216,11 +216,13 @@ 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?
namespace.store_security_reports_available? || public? namespace.store_security_reports_available? || public?
......
---
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