activerecord-session_store icon indicating copy to clipboard operation
activerecord-session_store copied to clipboard

Allow ActiveRecordStore.session_class to be evaluated lazily

Open gmcgibbon opened this issue 2 years ago • 3 comments

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

gmcgibbon avatar Sep 23 '23 00:09 gmcgibbon

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

byroot avatar Mar 26 '25 07:03 byroot

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.

gmcgibbon avatar Apr 17 '25 07:04 gmcgibbon

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?

byroot avatar Apr 17 '25 14:04 byroot