Skip to content
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

Make Active Record adapters connections lazy #42251

Closed
wants to merge 3 commits into from

Conversation

casperisfine
Copy link
Contributor

Context

This is a rebase of an old branch: https://github.com/Shopify/rails/tree/lazy-connection.

Related: #42085

For resiliency reasons, it is paramount that Rails is able to boot even if it can't connect to the database, right now it is achieved by skipping Active Record attribute methods definition if an error happens (Ref: #40119).

But for historical reason, lots of important data is held by the Adapter and accessed through ActiveRecord::Base.connection, and that later does eagerly connect to the database.

If the Adapter would only connect when necessary, it would make it much easier to initialize the application without having a dependency on the database.

@casperisfine casperisfine force-pushed the lazy-adapters branch 3 times, most recently from 1f23b7d to 71b1c91 Compare May 18, 2021 12:39
@casperisfine
Copy link
Contributor Author

cc @eileencodes @jhawthorn

I still need to convert the postgres adapter, but the general idea is there.

@casperisfine
Copy link
Contributor Author

I still need to convert the postgres adapter

Hum, it's going to be a very tricky one. It has much more state initialized from the connection than other adapters :/

@rails-bot
Copy link

rails-bot bot commented Aug 16, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Aug 16, 2021
@rails-bot rails-bot bot removed the stale label Aug 16, 2021
@byroot byroot closed this Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants