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

Only define attribute methods from schema cache #33985

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@eugeneius
Member

eugeneius commented Sep 26, 2018

Followup to #33959.

To define the attribute methods for a model, Active Record needs to know the schema of the underlying table, which is usually achieved by making a request to the database. This is undesirable behaviour while the app is booting, for two reasons: it makes the boot process dependent on the availability of the database, and it means every new process will make one query for each table, which can cause issues for large applications.

However, if the application is using the schema cache dump feature, then the schema cache already contains the necessary information, and we can define the attribute methods without causing any extra database queries.

r? @rafaelfranca

Only define attribute methods from schema cache
To define the attribute methods for a model, Active Record needs to know
the schema of the underlying table, which is usually achieved by making
a request to the database. This is undesirable behaviour while the app
is booting, for two reasons: it makes the boot process dependent on the
availability of the database, and it means every new process will make
one query for each table, which can cause issues for large applications.

However, if the application is using the schema cache dump feature, then
the schema cache already contains the necessary information, and we can
define the attribute methods without causing any extra database queries.

@rails-bot rails-bot bot added the railties label Sep 28, 2018

@oniofchaos

This comment has been minimized.

Show comment
Hide comment
@oniofchaos

oniofchaos Oct 13, 2018

Contributor

👍

Contributor

oniofchaos commented Oct 13, 2018

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment