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

.disable!(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 disabling for offending blocks of code.



25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/query_limiting.rb', line 25

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

  Gitlab::SafeRequestStore[:query_limiting_disabled] = true
end

.enable!Object

Enables query limiting for the request.



37
38
39
# File 'lib/gitlab/query_limiting.rb', line 37

def self.enable!
  Gitlab::SafeRequestStore[:query_limiting_disabled] = nil
end

.enabled?Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/gitlab/query_limiting.rb', line 13

def self.enabled?
  enabled_for_env? &&
    !Gitlab::SafeRequestStore[:query_limiting_disabled]
end

.enabled_for_env?Boolean

Returns true if we should enable tracking of query counts.

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.

Returns:

  • (Boolean)


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

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