This project is archived and is in readonly mode.
Reload routes on each request in dev mode
-
José Valim
- State changed from needs-more-info to wontfix
Loading routes in all requests can hit performance hard, so it's a no go about this (note: I'm Devise core developer).
-
Adam Williams
- Importance changed from to Low
I hope this is an appropriate place to bring this up...
Since the routes are only reloaded when the mtime of the file has changed, any auto-loaded constants referenced in the routes file are not 'replaced' when their source file is reloaded after Dependencies.clear.
For instance:
match '/abc' => MyAutoloadedEndpointWhen Dependencies.clear has been run, and I have modified the source for MyAutoloadedEndpoint, things get weird. The constant is no longer defined, but the route set is still referencing that old code. If the call method of the endpoint then causes an auto load of another class, const_missing attempts to resolve it by utilizing a nesting process that will then auto load MyAutoloadedEndpoint!
Am I off my rocker? I have solved this for myself by adding, in an config/initializer/endpoints.rb, this bit of code:
if Rails.env == "development" lib_reloader = ActiveSupport::FileUpdateChecker.new(Dir["app/endpoints/**/*"], true) do Rails.application.reload_routes! end ActionDispatch::Callbacks.to_prepare do lib_reloader.execute_if_updated end endI'd love you're feedback, or pointers on where to talk about this. Thank you.