diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 13:18:24 +0000 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /app/models/preloaders/commit_status_preloader.rb | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) | |
download | gitlab-ce-0653e08efd039a5905f3fa4f6e9cef9f5d2f799c.tar.gz |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'app/models/preloaders/commit_status_preloader.rb')
-rw-r--r-- | app/models/preloaders/commit_status_preloader.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/models/preloaders/commit_status_preloader.rb b/app/models/preloaders/commit_status_preloader.rb new file mode 100644 index 00000000000..535dd24ba6b --- /dev/null +++ b/app/models/preloaders/commit_status_preloader.rb @@ -0,0 +1,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 |