Skip to content

Commit e3cc8fe

Browse files
committed
Only enable routing source locations when using routes command
The overhead isn't necessary for development when not using the routes command. We can omit it entirely by checking for existence of the routes command constant.
1 parent 99fd4c0 commit e3cc8fe

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

actionpack/lib/action_dispatch/railtie.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ class Railtie < Rails::Railtie # :nodoc:
6868
config.action_dispatch.always_write_cookie = Rails.env.development? if config.action_dispatch.always_write_cookie.nil?
6969
ActionDispatch::Cookies::CookieJar.always_write_cookie = config.action_dispatch.always_write_cookie
7070

71-
ActionDispatch::Routing::Mapper.route_source_locations = Rails.env.development?
72-
7371
ActionDispatch::Http::Cache::Request.strict_freshness = app.config.action_dispatch.strict_freshness
7472
ActionDispatch.test_app = app
7573
end

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require "active_support/core_ext/enumerable"
77
require "active_support/core_ext/array/extract_options"
88
require "active_support/core_ext/regexp"
9+
require "action_dispatch/routing"
910
require "action_dispatch/routing/redirection"
1011
require "action_dispatch/routing/endpoint"
1112

railties/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Enable tracking route source locations only when using routes command. Previously,
2+
it was enabled in development mode, but is only needed for `bin/rails routes -E`.
3+
4+
*Gannon McGibbon*
5+
16
* Deprecate `bin/rake stats` in favor of `bin/rails stats`.
27

38
*Juan Vásquez*

railties/lib/rails/commands/routes/routes_command.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def invoke_command(*)
2222

2323
desc "routes", "List all the defined routes"
2424
def perform(*)
25+
require "action_dispatch/routing/mapper"
26+
ActionDispatch::Routing::Mapper.route_source_locations = true
2527
boot_application!
2628
require "action_dispatch/routing/inspector"
2729

railties/test/commands/routes_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ class Rails::Command::RoutesTest < ActiveSupport::TestCase
403403
assert_includes(output, "No unused routes found.")
404404
end
405405

406+
test "route source locations aren't included when booted normally" do
407+
output = rails "runner", "print !!ActionDispatch::Routing::Mapper.route_source_locations"
408+
409+
assert_equal("false", output)
410+
end
411+
406412
private
407413
def run_routes_command(args = [])
408414
rails "routes", args

0 commit comments

Comments
 (0)