-
Notifications
You must be signed in to change notification settings - Fork 885
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
Fix lazy load rails #1237
Fix lazy load rails #1237
Conversation
Create railtie with lazy load ActionController and ActiveRecord Rearrange file requiring for Rails and non Rails to make sure ActiveRecord is lazy loaded properly. Add CHANGELOG.md entry
a0ea4c9
to
9ac96ce
Compare
Hi @jaredbeck, when it's convenient can you please help review? |
Thanks for taking this on, Eric. This will require careful review. I've always found The Rails Initialization Process to be a difficult topic, and I'm not sure how well our test suite covers it. I also need to review PT's "railtie history". For example, Sorry for thinking out loud here, but those are some of the things that I'd like to understand better before reviewing this. |
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.
OK, I've spent a little time playing with this.
- I'm in favor of lazy loading, in principle. Specifically, I agree that the early
require "active_record"
inlib/paper_trail.rb
seems wrong. - This PR introduces
PaperTrail::Railtie
, but we already havePaperTrail::Rails::Engine
. AnEngine
is aRailtie
, so: is it OK to have both, and if so, why would we want both? If we decide to merge the two, which do we keep? - Most people have some PaperTrail configuration in an initializer of their own,
config/initializers/paper_trail.rb
. The documentation encourages this. I assume we want the end-user's initializer to happen last? If so, is there a way to make that explicit in code? - I'd like to have a lot more comments in the code. I work with these concepts (engines, railties) so rarely. It would be helpful to have comments explaining the order of operations, and linking to rails docs/guides/source. I can write some of these comments as I review this PR and learn more, but if anyone else wants to add some it'd be appreciated.
- What is the best way to test these changes?
See railties-6.0.2.2/lib/rails/railtie.rb:45
I found a little issue within our stack since AR is loaded properly. It's about abstract_class We encountered this error :
Basically, since Rails 5.0, all models inherits from module PaperTrail
# This is the default ActiveRecord model provided by PaperTrail. Most simple
# applications will use this model as-is, but it is possible to sub-class,
# extend, or even do without this model entirely. See documentation section
# 6.a. Custom Version Classes.
#
# The paper_trail-association_tracking gem provides a related model,
# `VersionAssociation`.
class Version < ::ActiveRecord::Base
include PaperTrail::VersionConcern
self.abstract_class = true if PaperTrail.config.version_is_abstract
end
end I guess it would be simpler than overriding. |
We can change Before raising any new topics, please let's address my questions above. Thanks. |
ActiveSupport.run_load_hooks(:paper_trail, self) Then people could hook in their app like this : ActiveSupport.on_load(:paper_trail) do
# user's code
end 4 : Sure adding comments is great idea. About my last_comment, I would suggest the config way instead of the |
I think so too. I'm looking at our engine and I don't think we need any of it. Please let me know when you've made this change and I'll review again.
I'd like to find a solution that doesn't require people to change their app code.
I'm not comfortable merging this without testing. Please research some other railtie-based gems and find out how they test their railtie. Thanks. |
Hi Eric, Still working on this? Want me to keep it open? Any guidance you need from me? Thanks! |
An effort begun by Eric Proulx in #1237 - Replaces Engine with simpler Railtie - Critically, defers certain `requires` - With Rails, defers via a Lazy Load Hook in the Railtie - Without Rails, just by require-ing AR first
Superseded by #1281, preserving your authorship, Eric. |
An effort begun by Eric Proulx in #1237 - Replaces Engine with simpler Railtie - Critically, defers certain `requires` - With Rails, defers via a Lazy Load Hook in the Railtie - Without Rails, just by require-ing AR first
Hello,
When running bumbler on our app, I found that
paper_trail
wasn't lazy loadingActiveRecord
properly because it's requiringactive_record
.So, I've created a railtie to lazy load
ActionController
andActiveRecord
. I also rearranged some file require to make sure it wont forceActiveRecord
to load.