summaryrefslogtreecommitdiff
path: root/config/initializers/active_record_preloader.rb
blob: 198c97cb8498813cc862d15c43c3d28981b61b05 (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
30
31
# frozen_string_literal: true

module ActiveRecord
  module Associations
    class Preloader
      class NullPreloader
        def self.new(*args, **kwargs)
          self
        end

        def self.run
          self
        end

        def self.preloaded_records
          []
        end
      end

      module NoCommitPreloader
        def preloader_for(reflection, owners)
          return NullPreloader if owners.first.association(reflection.name).klass == ::Commit

          super
        end
      end

      prepend NoCommitPreloader
    end
  end
end