diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /app/models/preloaders | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'app/models/preloaders')
3 files changed, 75 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 diff --git a/app/models/preloaders/merge_requests_preloader.rb b/app/models/preloaders/merge_requests_preloader.rb new file mode 100644 index 00000000000..cefe8408cab --- /dev/null +++ b/app/models/preloaders/merge_requests_preloader.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Preloaders + class MergeRequestsPreloader + attr_reader :merge_requests + + def initialize(merge_requests) + @merge_requests = merge_requests + end + + def execute + preloader = ActiveRecord::Associations::Preloader.new + preloader.preload(merge_requests, { target_project: [:project_feature] }) + merge_requests.each do |merge_request| + merge_request.lazy_upvotes_count + end + end + end +end diff --git a/app/models/preloaders/user_max_access_level_in_groups_preloader.rb b/app/models/preloaders/user_max_access_level_in_groups_preloader.rb new file mode 100644 index 00000000000..14f1d271572 --- /dev/null +++ b/app/models/preloaders/user_max_access_level_in_groups_preloader.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Preloaders + # This class preloads the max access level (role) for the user within the given groups and + # stores the values in requests store. + # Will only be able to preload max access level for groups where the user is a direct member + class UserMaxAccessLevelInGroupsPreloader + include BulkMemberAccessLoad + + def initialize(groups, user) + @groups = groups + @user = user + end + + def execute + group_memberships = GroupMember.active_without_invites_and_requests + .non_minimal_access + .where(user: @user, source_id: @groups) + .group(:source_id) + .maximum(:access_level) + + group_memberships.each do |group_id, max_access_level| + merge_value_to_request_store(User, @user.id, group_id, max_access_level) + end + end + end +end |