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

commit_status_preloader.rb « preloaders « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 535dd24ba6bdc29dd7409847b0c640f3a94edf38 (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 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