Welcome to mirror list, hosted at ThFree Co, Russian Federation.

active_record_subtransaction_methods.rb « performance « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b89d3ab8588e13f6b97ae5260890850aea69dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module RuboCop
  module Cop
    module Performance
      # Cop that disallows certain methods that rely on subtransactions in their implementation.
      # Companion to Performance/ActiveRecordSubtransactions, which bans direct usage of subtransactions.
      class ActiveRecordSubtransactionMethods < RuboCop::Cop::Cop
        MSG = 'Methods that rely on subtransactions should not be used. ' \
          'For more information see: https://gitlab.com/gitlab-org/gitlab/-/issues/338346'

        DISALLOWED_METHODS = %i[
          safe_ensure_unique
          safe_find_or_create_by
          safe_find_or_create_by!
          with_fast_read_statement_timeout
          create_or_find_by
          create_or_find_by!
        ].to_set.freeze

        def on_send(node)
          return unless DISALLOWED_METHODS.include?(node.method_name)

          add_offense(node, location: :selector)
        end
      end
    end
  end
end