Skip to content

Allow ActiveRecordStore.session_class to be evaluated lazily #208

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gmcgibbon
Copy link
Member

Prevents Active Record from being loaded early in an initializer (where the session_class is being set. This can slow down application boot time.

Prevents Active Record from being loaded early in an initializer (where
the session_class is being set. This can slow down application boot time.
@byroot byroot force-pushed the lazy_load_session_class branch from d2d7c38 to 825f9c3 Compare March 26, 2025 07:50
@byroot
Copy link
Member

byroot commented Mar 26, 2025

Hum, how does this work with reloading? Isn't the solution to set it in to_prepare?

@gmcgibbon
Copy link
Member Author

Right, I think we would still need to use to_prepare, but we don't want to load Active Record on application boot. Using a proc or a string would allow this, along with the setter clearing the instance ivar should cover both of our concerns. For apps that don't care about the load penalty, they can still use a plain old to_prepare with the base class.

@byroot
Copy link
Member

byroot commented Apr 17, 2025

but we don't want to load Active Record on application boot.

Then:

ActiveSupport.on_load(:active_record) do 
  config.to_prepare do
    # ....
  end
end

Or am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants