Commit d6e2201f authored by Tiger Watson's avatar Tiger Watson

Merge branch '333515-linear-queries-for-groupsfinder' into 'master'

Resolve "Linear queries for GroupsFinder"

See merge request gitlab-org/gitlab!67650
parents ba80ab37 53076f2e
...@@ -52,7 +52,16 @@ class GroupsFinder < UnionFinder ...@@ -52,7 +52,16 @@ class GroupsFinder < UnionFinder
return [Group.all] if current_user&.can_read_all_resources? && all_available? return [Group.all] if current_user&.can_read_all_resources? && all_available?
groups = [] groups = []
groups << Gitlab::ObjectHierarchy.new(groups_for_ancestors, groups_for_descendants).all_objects if current_user
if current_user
if Feature.enabled?(:use_traversal_ids_groups_finder, default_enabled: :yaml)
groups << current_user.authorized_groups.self_and_ancestors
groups << current_user.groups.self_and_descendants
else
groups << Gitlab::ObjectHierarchy.new(groups_for_ancestors, groups_for_descendants).all_objects
end
end
groups << Group.unscoped.public_to_user(current_user) if include_public_groups? groups << Group.unscoped.public_to_user(current_user) if include_public_groups?
groups << Group.none if groups.empty? groups << Group.none if groups.empty?
groups groups
...@@ -72,9 +81,13 @@ class GroupsFinder < UnionFinder ...@@ -72,9 +81,13 @@ class GroupsFinder < UnionFinder
.groups .groups
.where('members.access_level >= ?', params[:min_access_level]) .where('members.access_level >= ?', params[:min_access_level])
Gitlab::ObjectHierarchy if Feature.enabled?(:use_traversal_ids_groups_finder, default_enabled: :yaml)
.new(groups) groups.self_and_descendants
.base_and_descendants else
Gitlab::ObjectHierarchy
.new(groups)
.base_and_descendants
end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
---
name: use_traversal_ids_groups_finder
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67650
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/345666
milestone: '14.6'
type: development
group: group::access
default_enabled: false
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe GroupsFinder do RSpec.describe GroupsFinder do
include AdminModeHelper include AdminModeHelper
describe '#execute' do shared_examples '#execute' do
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'root level groups' do describe 'root level groups' do
...@@ -20,6 +20,7 @@ RSpec.describe GroupsFinder do ...@@ -20,6 +20,7 @@ RSpec.describe GroupsFinder do
user_private_group) user_private_group)
:regular | { all_available: false } | %i(user_public_group user_internal_group user_private_group) :regular | { all_available: false } | %i(user_public_group user_internal_group user_private_group)
:regular | {} | %i(public_group internal_group user_public_group user_internal_group user_private_group) :regular | {} | %i(public_group internal_group user_public_group user_internal_group user_private_group)
:regular | { min_access_level: Gitlab::Access::DEVELOPER } | %i(user_public_group user_internal_group user_private_group)
:external | { all_available: true } | %i(public_group user_public_group user_internal_group user_private_group) :external | { all_available: true } | %i(public_group user_public_group user_internal_group user_private_group)
:external | { all_available: false } | %i(user_public_group user_internal_group user_private_group) :external | { all_available: false } | %i(user_public_group user_internal_group user_private_group)
...@@ -261,4 +262,16 @@ RSpec.describe GroupsFinder do ...@@ -261,4 +262,16 @@ RSpec.describe GroupsFinder do
end end
end end
end end
describe '#execute' do
include_examples '#execute'
context 'when use_traversal_ids_groups_finder feature flags is disabled' do
before do
stub_feature_flags(use_traversal_ids_groups_finder: false)
end
include_examples '#execute'
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment