diff --git a/app/finders/fork_targets_finder.rb b/app/finders/fork_targets_finder.rb index a96acd5838e662012697400c49a0d3e414b0c774..4c40c0d7b280ca4f6bb1c45f4d4e723be8f349c3 100644 --- a/app/finders/fork_targets_finder.rb +++ b/app/finders/fork_targets_finder.rb @@ -19,7 +19,17 @@ def execute(options = {}) def by_search(items, options) return items if options[:search].blank? - items.search(options[:search]) + if Feature.enabled?(:fork_targets_finder_with_parents, user) + # Ideally, we should use `items.search(options[:search], include_parents: true)` option + # But the resulted query has a terrible performance. See issue: https://gitlab.com/gitlab-org/gitlab/-/issues/437731. + # + # As a workaround, we can fetch the group's name from the path and search by it. + search = options[:search].to_s.split('/').last + + items.search(search) + else + items.search(options[:search]) + end end def fork_targets(options) diff --git a/config/feature_flags/gitlab_com_derisk/fork_targets_finder_with_parents.yml b/config/feature_flags/gitlab_com_derisk/fork_targets_finder_with_parents.yml new file mode 100644 index 0000000000000000000000000000000000000000..a3dca057dbc2f4b663912171c30cbd7a5d059e37 --- /dev/null +++ b/config/feature_flags/gitlab_com_derisk/fork_targets_finder_with_parents.yml @@ -0,0 +1,9 @@ +--- +name: fork_targets_finder_with_parents +feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/378243 +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/145230 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/442392 +milestone: '16.11' +group: group::source code +type: gitlab_com_derisk +default_enabled: false diff --git a/spec/finders/fork_targets_finder_spec.rb b/spec/finders/fork_targets_finder_spec.rb index 746c48a8fabe376f95c4998e2970b1a97e90b107..541ace7e8c81044a8f81e120d98d2963258250bd 100644 --- a/spec/finders/fork_targets_finder_spec.rb +++ b/spec/finders/fork_targets_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ForkTargetsFinder do +RSpec.describe ForkTargetsFinder, feature_category: :source_code_management do subject(:finder) { described_class.new(project, user) } let_it_be(:project) { create(:project, namespace: create(:group)) } @@ -75,6 +75,24 @@ it 'filters the targets by the param' do expect(finder.execute(search: maintained_group.path)).to eq([maintained_group]) end + + context 'when searching by a full path' do + let_it_be(:subgroup) { create(:group, :nested, parent: maintained_group) } + + it 'returns a group for an exact match' do + expect(finder.execute(search: subgroup.full_path)).to eq([subgroup]) + end + + context 'when feature flag "fork_targets_finder_with_parents" is disabled' do + before do + stub_feature_flags(fork_targets_finder_with_parents: false) + end + + it 'does not return a group' do + expect(finder.execute(search: subgroup.full_path)).to eq([]) + end + end + end end end end