Ensure application gets reloaded only once#5740
Ensure application gets reloaded only once#5740javierjulio merged 2 commits intoactiveadmin:masterfrom
Conversation
|
I love this ❤️. One thought and two nitpicks. Maybe we should land the #5732 PR first, in case this conflicts with Zeitwerk. In particular, I think the spec you have added will need to run with the As nitpicks, I'd love if you could split the PR into two separate commits, one that removes the unnecessary compatibility layer with the Rails reloader, and another one that fixes the double loading issue. The other one is that the "integration_spec.rb" file we could maybe be renamed to "rails_integration_spec.rb" |
|
Sure, no problem. I’ll get to it tomorrow or Monday. |
f10d5e5 to
86fe8eb
Compare
|
@deivid-rodriguez all done. I've also merged your (And yes I've run the specs with |
* 5739-reload-once: Ensure application gets reloaded only once Remove reloader compatibility layer
|
This looks good to me! Thanks @jscheid! Just in case, can you rebase this since there's been a few changes in |
|
Oh, can you also add a changelog entry for the reloading fix? |
86fe8eb to
cac0589
Compare
|
@deivid-rodriguez rebased... could you add the change log please? I don't know what version it will be released in. |
|
You don't need to know it, put it under the "Unreleased" section. Anyways, I can do it, no problem 😃 |
|
Ah, now it did break. Good call. Curious, because it definitely didn't the other day (with Zeitwerk merged in). I'll have another look at this tomorrow 😕 |
|
Great, thanks! |
|
I plan to release this with 2.1 by the way, together with "official" Rails 6 support. |
cac0589 to
b2e5f7c
Compare
This is no longer needed now that support for Rails 4.x has been dropped.
b2e5f7c to
dbde7d8
Compare
|
@deivid-rodriguez any idea what the codeclimate failure is about? I'm inclined to think it's a bug... I had pushed the same change before with the only difference in the change log, and it didn't complain. |
|
|
dbde7d8 to
66e40c4
Compare
|
Since you're adding a new "suite", you need to make sure coverage reports are properly merged together. You should create a new |
|
@deivid-rodriguez there are already cucumber specs for this type. Were they not considered for code coverage before? |
|
Cucumber reloading specs are also part of a separate suite, which is properly configured for coverage report merging. Basically every set of specs/features that run as a separate process needs custom code so that their coverage reports are properly merged. |
|
Ah, I think we're good: https://github.com/activeadmin/activeadmin/blob/master/features/support/simplecov_reload_env.rb I think problem was just that the new type didn't run in CI. 🤞 |
66e40c4 to
21b6138
Compare
|
You were right, that file was missing. What a drag... you're lucky you got your PR in before mine 😉 Should be all good now? |
javierjulio
left a comment
There was a problem hiding this comment.
Looks great, thank you! 👏🏻
|
You're welcome, thanks for merging. |
I've recently used ruby-prof to look at reload performance, like so:
Doing so revealed that
ActiveAdmin.application.load!is called twice. Since that method accounts for a substantial portion of the time it takes to reload our app, this seems quite wasteful.The reason is that the
preparecallback is invoked twice, from here:https://github.com/rails/rails/blob/v5.2.3/activesupport/lib/active_support/reloader.rb#L46
and from here:
https://github.com/rails/rails/blob/v5.2.3/activesupport/lib/active_support/reloader.rb#L59
For the "load" callback alone this wouldn't be a problem because it only calls
load!if the application is not already loaded. However, the "unload" callback also uses thepreparecallback, which results in the following order of callbacks:That defeats the
loaded?guard because by the time the "load" callback is invoked a second time, the application has been unloaded again.This PR attempts to solve the problem by using the
class_unloadevent instead of theprepareevent for the "unload" callback. That event is only invoked once per reload.It also removes the compatibility layer in
reloader.rb. As far as I can tell, it is no longer needed now that support for Rails 4.x has been dropped.It also simplifies the logic for registering the "unload" callback because the same callback works regardless of the setting for
reload_classes_only_on_change.Closes #5739