From 84d1bd786125c1c14a3ba5f63e38a4cc736a9027 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 16 Jan 2024 10:42:19 +0000 Subject: Add latest changes from gitlab-org/gitlab@16-8-stable-ee --- app/models/concerns/routable.rb | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'app/models/concerns/routable.rb') diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 242194be440..43874d0211c 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -87,37 +87,27 @@ module Routable # Klass.where_full_path_in(%w{gitlab-org/gitlab-foss gitlab-org/gitlab}) # # Returns an ActiveRecord::Relation. - def where_full_path_in(paths, use_includes: true) + def where_full_path_in(paths, preload_routes: true) return none if paths.empty? - wheres = paths.map do |path| + path_condition = paths.map do |path| "(LOWER(routes.path) = LOWER(#{connection.quote(path)}))" - end + end.join(' OR ') - if Feature.enabled?(:optimize_where_full_path_in, Feature.current_request) - route_scope = all - source_type_condition = { source_type: route_scope.klass.base_class } + route_scope = all + source_type_condition = { source_type: route_scope.klass.base_class } - routes_matching_condition = Route.where(source_type_condition).where(wheres.join(' OR ')) + routes_matching_condition = Route + .where(source_type_condition) + .where(path_condition) - result = route_scope.where(id: routes_matching_condition.pluck(:source_id)) + source_ids = routes_matching_condition.pluck(:source_id) + result = route_scope.where(id: source_ids) - if use_includes - result.preload(:route) - else - result - end + if preload_routes + result.preload(:route) else - route = - if use_includes - includes(:route).references(:routes) - else - joins(:route) - end - - route - .where(wheres.join(' OR ')) - .allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/420046") + result end end end -- cgit v1.2.3