forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer route drawing to the first request, or when url_helpers called.
Executes the first routes reload in middleware, or when the route set url_helpers is called. Previously, this was executed unconditionally on boot, which can slow down boot time unnecessarily for larger apps with lots of routes.
- Loading branch information
Showing
24 changed files
with
374 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
# :markup: markdown | ||
|
||
require "action_dispatch/routing/route_set" | ||
|
||
module Rails | ||
class Engine | ||
class RouteSet < ActionDispatch::Routing::RouteSet # :nodoc: | ||
class NamedRouteCollection < ActionDispatch::Routing::RouteSet::NamedRouteCollection | ||
def route_defined?(name) | ||
Rails.application&.reload_routes_unless_loaded | ||
|
||
super(name) | ||
end | ||
end | ||
|
||
def initialize(config = DEFAULT_CONFIG) | ||
super | ||
self.named_routes = NamedRouteCollection.new | ||
named_routes.url_helpers_module.prepend(method_missing_module) | ||
named_routes.path_helpers_module.prepend(method_missing_module) | ||
end | ||
|
||
def generate_extras(options, recall = {}) | ||
Rails.application&.reload_routes_unless_loaded | ||
|
||
super(options, recall) | ||
end | ||
|
||
private | ||
def method_missing_module | ||
@method_missing_module ||= Module.new do | ||
private | ||
def method_missing(method_name, *args, &block) | ||
if Rails.application&.reload_routes_unless_loaded | ||
public_send(method_name, *args, &block) | ||
else | ||
super(method_name, *args, &block) | ||
end | ||
end | ||
|
||
def respond_to_missing?(method_name, *args) | ||
if Rails.application&.reload_routes_unless_loaded | ||
respond_to?(method_name, *args) | ||
else | ||
super(method_name, *args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Rails | ||
module Rack | ||
class LoadRoutes | ||
def initialize(app) | ||
@app = app | ||
@called = false | ||
end | ||
|
||
def call(env) | ||
@called ||= begin | ||
Rails.application.reload_routes_unless_loaded | ||
true | ||
end | ||
@app.call(env) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.