From ba2d7eda617fadad5010a8c3cf054af795693927 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 30 Jan 2017 11:35:28 +0200 Subject: [PATCH] Improve search within group logic Signed-off-by: Dmitriy Zaporozhets --- app/models/project.rb | 1 + app/services/search/global_service.rb | 3 +-- spec/models/project_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 4396ea9ef36..37f4705adbd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -225,6 +225,7 @@ class Project < ActiveRecord::Base scope :with_project_feature, -> { joins('LEFT JOIN project_features ON projects.id = project_features.project_id') } scope :with_statistics, -> { includes(:statistics) } scope :with_shared_runners, -> { where(shared_runners_enabled: true) } + scope :inside_path, ->(path) { joins(:route).where('routes.path LIKE ?', "#{path}/%") } # "enabled" here means "not disabled". It includes private features! scope :with_feature_enabled, ->(feature) { diff --git a/app/services/search/global_service.rb b/app/services/search/global_service.rb index d477a5d3c7e..781cd13b44b 100644 --- a/app/services/search/global_service.rb +++ b/app/services/search/global_service.rb @@ -11,8 +11,7 @@ module Search projects = ProjectsFinder.new.execute(current_user) if group - ids = group.descendants.push(group.id) - projects = projects.in_namespace(ids) + projects = projects.inside_path(group.full_path) end Gitlab::SearchResults.new(current_user, projects, params[:search]) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 527eb704036..48b085781e7 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1833,6 +1833,14 @@ describe Project, models: true do end end + describe 'inside_path' do + let!(:project1) { create(:empty_project) } + let!(:project2) { create(:empty_project) } + let!(:path) { project1.namespace.path } + + it { expect(Project.inside_path(path)).to eq([project1]) } + end + def enable_lfs allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) end