New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only execute route reloads once on boot for development environment #40742
Only execute route reloads once on boot for development environment #40742
Conversation
252341b
to
1680429
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff and nice finding. Can we add a test to make sure only 1 route reload happens in boot? This will make sure we don't regress again.
1680429
to
dcf5f5e
Compare
paths.each { |path| load(path) } | ||
run_callbacks :load_paths do | ||
paths.each { |path| load(path) } | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the callback setup feels like we could just do this?
def load_paths
paths.each { |path| load(path) }
after_load_path_callback&.call
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca had suggested this but it might very well be faster not to use the activesupport callbacks? I have no strong feelings either way and am happy to make changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it after the merge
@@ -173,6 +173,22 @@ def self.complete(_state) | |||
end | |||
end | |||
|
|||
initializer :add_builtin_route do |app| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initializer :add_builtin_route do |app| | |
initializer :add_internal_routes do |app| |
Can we rename this without anyone relying on the initializer name? Feels like we aren't adding just one more anymore and internal would be closer than builtin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone ahead and made this change but will leave the comment unresolved if only so others can notice this change.
Signed-off-by: Louis Cloutier <louis.cloutier@shopify.com>
dcf5f5e
to
796e712
Compare
@dotLou thank you, this was great 🙌 |
Signed-off-by: Louis Cloutier louis.cloutier@shopify.com
Summary
In #39980 a new supported use case was added to allow overriding of the welcome route in an app via
get '/'
. Unfortunately, this introduced a doubleroutes_reloader.execute
in the development environment. For apps with lots of routes and/or lots of routes files, this creates a significant expense when booting in development environments.This PR aims to allow for that use case while only executing the routes reloader a single time. To do this, I've introduced a new callback that can be set via Proc on the routes reloader, and will be called after
load_paths
.You can see that the number of items is decreased in the
LoadingTest
, back to its original number, and the existing tests should continue to pass (and support overriding of the welcome route via bothroot
andget '/'
route definitions).Other Information
I've gone ahead and updated the changelog already, but please let me know if I should remove that or alter the text in any way.