aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-08-01 15:07:01 +0200
committerJosé Valim <jose.valim@gmail.com>2012-08-21 14:46:12 -0300
commite6747d87f3a061d153215715d56acbb0be20191f (patch)
tree7466bf0ceff18642e3e1d154419b05d6414e2be0 /railties/lib/rails/generators
parentdf1a5e492ae178856f6cf92ae70ce620f4cd0613 (diff)
downloadrails-e6747d87f3a061d153215715d56acbb0be20191f.tar.gz
rails-e6747d87f3a061d153215715d56acbb0be20191f.tar.bz2
rails-e6747d87f3a061d153215715d56acbb0be20191f.zip
Allow users to choose when to eager_load the application or not.
Previously, the eager load behavior was mostly coupled to config.cache_classes, however this was suboptimal since in some environments a developer may want to cache classes but not necessarily load them all on boot (for example, test env). This pull request also promotes the use of config.eager_load set to true by default in production. In the majority of the cases, this is the behavior you want since it will copy most of your app into memory on boot (which was also the previous behavior). Finally, this fix a long standing Rails bug where it was impossible to access a model in a rake task when Rails was set as thread safe.
Diffstat (limited to 'railties/lib/rails/generators')
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt5
3 files changed, 14 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 2016eb8b05..122e7e2b34 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -6,6 +6,9 @@
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
+ # Do not eager load code on boot.
+ config.eager_load = false
+
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 80413be0d3..a627636089 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -4,6 +4,12 @@
# Code is not reloaded between requests.
config.cache_classes = true
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both thread web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
index 878deb49d7..8ab27eb6e1 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
@@ -7,6 +7,11 @@
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"