diff --git a/lib/gitlab/query_limiting.rb b/lib/gitlab/query_limiting.rb index 31e6b120e4518e44216f3b48637ea12fa924ae1e..5e46e26e14e120011032448b5fb574644841d7b5 100644 --- a/lib/gitlab/query_limiting.rb +++ b/lib/gitlab/query_limiting.rb @@ -4,9 +4,8 @@ module Gitlab module QueryLimiting # Returns true if we should enable tracking of query counts. # - # This is only enabled in production/staging if we're running on GitLab.com. - # This ensures we don't produce any errors that users can't do anything - # about themselves. + # This is only enabled in development and test to ensure we don't produce + # any errors that users of other environments can't do anything about themselves. def self.enable? Rails.env.development? || Rails.env.test? end @@ -19,7 +18,7 @@ def self.enable? # The issue URL is only meant to push developers into creating an issue # instead of blindly whitelisting offending blocks of code. def self.whitelist(issue_url) - return unless enable_whitelist? + return unless enable? unless issue_url.start_with?('https://') raise( @@ -30,9 +29,5 @@ def self.whitelist(issue_url) Transaction&.current&.whitelisted = true end - - def self.enable_whitelist? - Rails.env.development? || Rails.env.test? - end end end diff --git a/spec/lib/gitlab/query_limiting_spec.rb b/spec/lib/gitlab/query_limiting_spec.rb index 0fcd865567d1721331a778317a4802654827e294..4f70c65adca67bfe2c4cb1de711e925d553c59d9 100644 --- a/spec/lib/gitlab/query_limiting_spec.rb +++ b/spec/lib/gitlab/query_limiting_spec.rb @@ -63,6 +63,20 @@ expect(transaction.count).to eq(before) end + + it 'whitelists when enabled' do + described_class.whitelist('https://example.com') + + expect(transaction.whitelisted).to eq(true) + end + + it 'does not whitelist when disabled' do + allow(described_class).to receive(:enable?).and_return(false) + + described_class.whitelist('https://example.com') + + expect(transaction.whitelisted).to eq(false) + end end end end