Skip to content

Commit

Permalink
Deprecate config.threadsafe!
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 21, 2012
1 parent 2801786 commit 5d416b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
12 changes: 6 additions & 6 deletions guides/source/configuring.textile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ end

* +config.dependency_loading+ is a flag that allows you to disable constant autoloading setting it to false. It only has effect if +config.cache_classes+ is true, which it is by default in production mode. This flag is set to false by +config.threadsafe!+.

* +config.eager_load+ when true, eager loads all registered `config.eager_load_namespaces`. This includes your application, engines, Rails frameworks and any other registered namespace.

* +config.eager_load_namespaces+ registers namespaces that are eager loaded when +config.eager_load+ is true. All namespaces in the list must respond to the +eager_load!+ method.

* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application.

* +config.encoding+ sets up the application-wide encoding. Defaults to UTF-8.
Expand Down Expand Up @@ -125,10 +129,6 @@ config.session_store :my_custom_store

This custom store must be defined as +ActionDispatch::Session::MyCustomStore+. In addition to symbols, they can also be objects implementing a certain API, like +ActiveRecord::SessionStore+, in which case no special namespace is required.

* +config.threadsafe!+ enables +cache_classes+ and +eager_load+ to make the application threadsafe.

WARNING: Threadsafe operation is incompatible with the normal workings of development mode Rails. In particular, automatic dependency loading and class reloading are automatically disabled when you call +config.threadsafe!+.

* +config.time_zone+ sets the default time zone for the application and enables time zone awareness for Active Record.

* +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments.
Expand Down Expand Up @@ -746,13 +746,13 @@ The error occurred while evaluating nil.each

*+build_middleware_stack+* Builds the middleware stack for the application, returning an object which has a +call+ method which takes a Rack environment object for the request.

*+eager_load!+* If +config.cache_classes+ is true, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all the Ruby files from +config.eager_load_paths+.
*+eager_load!+* If +config.eager_load+ is true, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all +config.eager_load_namespaces+.

*+finisher_hook+* Provides a hook for after the initialization of process of the application is complete, as well as running all the +config.after_initialize+ blocks for the application, railties and engines.

*+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+.

*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to true and +config.dependency_loading+ is set to false.
*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.eager_load+ is set to true.

h3. Database pooling

Expand Down
2 changes: 2 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
default_url_options[:script_name] to set proper application's mount point by
yourself. *Piotr Sarnacki*

* `config.threadsafe!` is deprecated in favor of `config.eager_load` which provides a more fine grained control on what is eager loaded *José Valim*

* The migration generator will now produce AddXXXToYYY/RemoveXXXFromYYY migrations with references statements, for instance

rails g migration AddReferencesToProducts user:references supplier:references{polymorphic}
Expand Down
7 changes: 3 additions & 4 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def paths
end
end

# Enable threaded mode. Allows concurrent requests to controller actions and
# multiple database connections. Also disables automatic dependency loading
# after boot, and disables reloading code on every request, as these are
# fundamentally incompatible with thread safety.
def threadsafe!
ActiveSupport::Deprecation.warn "config.threadsafe! is deprecated. Rails applications " \
"behave by default as thread safe in production as long as config.cache_classes and " \
"config.eager_load are set to true"
@cache_classes = true
@eager_load = true
self
Expand Down
21 changes: 9 additions & 12 deletions railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,31 @@ def teardown
assert_instance_of Pathname, Rails.root
end

test "marking the application as threadsafe sets the correct config variables" do
test "initialize an eager loaded, cache classes app" do
add_to_config <<-RUBY
config.threadsafe!
config.eager_load = true
config.cache_classes = true
RUBY

require "#{app_path}/config/application"
assert AppTemplate::Application.config.cache_classes
assert AppTemplate::Application.config.eager_load
assert AppTemplate::Application.initialize!
end

test "initialize a threadsafe app" do
add_to_config <<-RUBY
config.threadsafe!
RUBY

test "application is always added to eager_load namespaces" do
require "#{app_path}/config/application"
assert AppTemplate::Application.initialize!
assert AppTemplate::Application, AppTemplate::Application.config.eager_load_namespaces
end

test "asset_path defaults to nil for application" do
require "#{app_path}/config/environment"
assert_equal nil, AppTemplate::Application.config.asset_path
end

test "the application can be marked as threadsafe when there are no frameworks" do
test "the application can be eager loaded even when there are no frameworks" do
FileUtils.rm_rf("#{app_path}/config/environments")
add_to_config <<-RUBY
config.threadsafe!
config.eager_load = true
config.cache_classes = true
RUBY

use_frameworks []
Expand Down

0 comments on commit 5d416b9

Please sign in to comment.