debian-mirror-gitlab/app/models/preloaders/commit_status_preloader.rb

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

30 lines
649 B
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# frozen_string_literal: true
module Preloaders
class CommitStatusPreloader
CLASSES = [::Ci::Build, ::Ci::Bridge, ::GenericCommitStatus].freeze
def initialize(statuses)
@statuses = statuses
end
def execute(relations)
preloader = ActiveRecord::Associations::Preloader.new
CLASSES.each do |klass|
preloader.preload(objects(klass), associations(klass, relations))
end
end
private
def objects(klass)
@statuses.select { |job| job.is_a?(klass) }
end
def associations(klass, relations)
klass.reflections.keys.map(&:to_sym) & relations.map(&:to_sym)
end
end
end