diff --git a/config/application.rb b/config/application.rb index a8b6bc937cfb912a21f73171543ea7a1c9eadf9c..341cc36cbdb647920d1af52a942125dd97b3b185 100644 --- a/config/application.rb +++ b/config/application.rb @@ -368,30 +368,5 @@ class Application < Rails::Application end end end - - config.after_initialize do - # Devise (see initializers/8_devise.rb) already reloads routes if - # eager loading is enabled, so don't do this twice since it's - # expensive. - Rails.application.reload_routes! unless config.eager_load - - project_url_helpers = Module.new do - extend ActiveSupport::Concern - - Gitlab::Application.routes.named_routes.helper_names.each do |name| - next unless name.include?('namespace_project') - - define_method(name.sub('namespace_project', 'project')) do |project, *args| - send(name, project&.namespace, project, *args) - end - end - end - - # We add the MilestonesRoutingHelper because we know that this does not - # conflict with the methods defined in `project_url_helpers`, and we want - # these methods available in the same places. - Gitlab::Routing.add_helpers(project_url_helpers) - Gitlab::Routing.add_helpers(TimeboxesRoutingHelper) - end end end diff --git a/config/initializers/zz_metrics.rb b/config/initializers/zz_metrics.rb index 430e4d60d611d1616eaaf7832611671b443d55f0..a3771975950bb58c626167d5331176dd9ffe3ab7 100644 --- a/config/initializers/zz_metrics.rb +++ b/config/initializers/zz_metrics.rb @@ -154,9 +154,13 @@ def instrument_classes(instrumentation) # of the ActiveRecord methods. This has to take place _after_ initializing as # for some unknown reason calling eager_load! earlier breaks Devise. Gitlab::Application.config.after_initialize do - Rails.application.eager_load! + # We should move all the logic of this file to somewhere else + # and require it after `Rails.application.initialize!` in `environment.rb` file. + models_path = Rails.root.join('app', 'models').to_s - models = Rails.root.join('app', 'models').to_s + Dir.glob("**/*.rb", base: models_path).sort.each do |file| + require_dependency file + end regex = Regexp.union( ActiveRecord::Querying.public_instance_methods(false).map(&:to_s) @@ -172,7 +176,7 @@ def instrument_classes(instrumentation) else loc = method.source_location - loc && loc[0].start_with?(models) && method.source =~ regex + loc && loc[0].start_with?(models_path) && method.source =~ regex end end diff --git a/config/routes.rb b/config/routes.rb index 91d1a817175d9a002e58f865132b2653c17be30e..eee31730f8a3d3e9ab2b89ba9ad2b4ebcd481b81 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -287,7 +287,28 @@ get '/sitemap' => 'sitemap#show', format: :xml end + # Creates shorthand helper methods for project resources. + # For example; for the `namespace_project_path` this also creates `project_path`. + # + # TODO: We don't need the `Gitlab::Routing` module at all as we can use + # the `direct` DSL method of Rails to define url helpers. Move all the + # custom url helpers to use the `direct` DSL method and remove the `Gitlab::Routing`. + # For more information: https://gitlab.com/gitlab-org/gitlab/-/issues/299583 + Gitlab::Application.routes.set.filter_map { |route| route.name if route.name&.include?('namespace_project') }.each do |name| + new_name = name.sub('namespace_project', 'project') + + direct(new_name) do |project, *args| + # This is due to a bug I've found in Rails. + # For more information: https://gitlab.com/gitlab-org/gitlab/-/issues/299591 + args.pop if args.last == {} + + send("#{name}_url", project&.namespace, project, *args) + end + end + root to: "root#index" get '*unmatched_route', to: 'application#route_not_found' end + +Gitlab::Routing.add_helpers(TimeboxesRoutingHelper)