Module: Gitlab::QueryLimiting

Defined in:
lib/gitlab/query_limiting.rb,
lib/gitlab/query_limiting/middleware.rb,
lib/gitlab/query_limiting/transaction.rb,
lib/gitlab/query_limiting/active_support_subscriber.rb

Defined Under Namespace

Classes: ActiveSupportSubscriber, Middleware, Transaction

Class Method Summary collapse

Class Method Details

.enable?Boolean

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.

Returns:

  • (Boolean)

10
11
12
# File 'lib/gitlab/query_limiting.rb', line 10

def self.enable?
  Rails.env.development? || Rails.env.test?
end

.enable_whitelist?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'lib/gitlab/query_limiting.rb', line 34

def self.enable_whitelist?
  Rails.env.development? || Rails.env.test?
end

.whitelist(issue_url) ⇒ Object

Allows the current request to execute any number of SQL queries.

This method should only be used when there's a corresponding issue to reduce the number of queries.

The issue URL is only meant to push developers into creating an issue instead of blindly whitelisting offending blocks of code.


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/query_limiting.rb', line 21

def self.whitelist(issue_url)
  return unless enable_whitelist?

  unless issue_url.start_with?('https://')
    raise(
      ArgumentError,
      'You must provide a valid issue URL in order to whitelist a block of code'
    )
  end

  Transaction&.current&.whitelisted = true
end