10

Add ability to lazily load the schema cache on connection by eileencodes · Pull...

 2 years ago
source link: https://github.com/rails/rails/pull/43372
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Member

eileencodes commented 6 days ago

edited

This adds a configuration option and code to enable lazy loading of the
schema cache on the connection. If
config.active_record.lazily_load_schema_cache is set to true then
the Railtie will be completely skipped and the schema cache will be
loaded when the connection is established rather than on boot.

We use this method at GitHub currently in our custom adapter. It enables
us to load schema caches lazily. It also is a solution for schema caches
with multiple databases. The Railtie doesn't know about the other
connections before boot so it can only load the cache for
ActiveRecord::Base.connection. Since this loads the cache on
establish_connection Rails doesn't need to know anything special about
the connections.

Applications can continue dumping the cache like normal, the change is
only to how the schema cache is loaded. To use the lazy loaded schema
cache a schema_cache_path must be set in the database configuration,
otherwise db/schema_cache.yml will be used.

Followup questions:

  1. Should we deprecate the Railtie?
  2. The Railtie does more work than we're doing here because it checks
    the version against the current version. I'm not sure we really want
    to do this in Rails - we don't do it in ours at GitHub.

Notes:
This is basically an upstream of behavior we have at GitHub that lazily loads our schema cache when the connection is established rather than on boot.

cc/ @jhawthorn @matthewd
cc/ @casperisfine @tenderlove @rafaelfranca


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK