debian-mirror-gitlab/config/initializers/active_record_preloader.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
779 B
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module ActiveRecord
module Associations
class Preloader
2023-05-27 22:25:52 +05:30
def initialize(records: nil, associations: nil)
super()
@records = records
@associations = associations
end
def call
preload(@records, @associations)
end
2019-09-30 21:07:59 +05:30
class NullPreloader
2021-06-08 01:23:25 +05:30
def self.new(*args, **kwargs)
2019-09-30 21:07:59 +05:30
self
end
2020-03-13 15:44:24 +05:30
def self.run
2021-04-29 21:17:54 +05:30
self
2019-09-30 21:07:59 +05:30
end
def self.preloaded_records
[]
end
end
2017-09-10 17:25:29 +05:30
module NoCommitPreloader
2019-09-30 21:07:59 +05:30
def preloader_for(reflection, owners)
return NullPreloader if owners.first.association(reflection.name).klass == ::Commit
2017-09-10 17:25:29 +05:30
super
end
end
prepend NoCommitPreloader
end
end
end