diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-24 12:09:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-24 12:09:58 +0300 |
commit | 49cea0b04a1138a00cc7068c4c1a997867aeae88 (patch) | |
tree | 8fcb67c495910b1e29d3d103c67f4b5ab08f4486 /app/models/preloaders | |
parent | b8c4740f87d08217b970b6441eda28f79b78ecef (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/preloaders')
-rw-r--r-- | app/models/preloaders/group_policy_preloader.rb | 7 | ||||
-rw-r--r-- | app/models/preloaders/group_root_ancestor_preloader.rb | 32 |
2 files changed, 2 insertions, 37 deletions
diff --git a/app/models/preloaders/group_policy_preloader.rb b/app/models/preloaders/group_policy_preloader.rb index 95d6e0b5c1f..44030140ce3 100644 --- a/app/models/preloaders/group_policy_preloader.rb +++ b/app/models/preloaders/group_policy_preloader.rb @@ -8,15 +8,12 @@ module Preloaders end def execute - Preloaders::UserMaxAccessLevelInGroupsPreloader.new(@groups, @current_user).execute - Preloaders::GroupRootAncestorPreloader.new(@groups, root_ancestor_preloads).execute + Preloaders::UserMaxAccessLevelInGroupsPreloader.new(groups, current_user).execute end private - def root_ancestor_preloads - [] - end + attr_reader :groups, :current_user end end diff --git a/app/models/preloaders/group_root_ancestor_preloader.rb b/app/models/preloaders/group_root_ancestor_preloader.rb deleted file mode 100644 index 3ca713d9635..00000000000 --- a/app/models/preloaders/group_root_ancestor_preloader.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module Preloaders - class GroupRootAncestorPreloader - def initialize(groups, root_ancestor_preloads = []) - @groups = groups - @root_ancestor_preloads = root_ancestor_preloads - end - - def execute - return unless ::Feature.enabled?(:use_traversal_ids, default_enabled: :yaml) - - # type == 'Group' condition located on subquery to prevent a filter in the query - root_query = Namespace.joins("INNER JOIN (#{join_sql}) as root_query ON root_query.root_id = namespaces.id") - .select('namespaces.*, root_query.id as source_id') - - root_query = root_query.preload(*@root_ancestor_preloads) if @root_ancestor_preloads.any? - - root_ancestors_by_id = root_query.group_by(&:source_id) - - @groups.each do |group| - group.root_ancestor = root_ancestors_by_id[group.id].first - end - end - - private - - def join_sql - Group.select('id, traversal_ids[1] as root_id').where(id: @groups.map(&:id)).to_sql - end - end -end |