diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-08-21 12:58:25 -0700 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-08-21 12:58:25 -0700 |
commit | 6bef1469d2e43d0815b70588370470983a4320af (patch) | |
tree | 7d1f2f5cc9506507e02cc13d2b6ff7f614a8ca88 /railties/lib/rails/application | |
parent | 11e890fef8982caa206e4fbc033f896e6ad424a1 (diff) | |
parent | da3d28ea33a7e418c99e89aa6b4028ba054f1f39 (diff) | |
download | rails-6bef1469d2e43d0815b70588370470983a4320af.tar.gz rails-6bef1469d2e43d0815b70588370470983a4320af.tar.bz2 rails-6bef1469d2e43d0815b70588370470983a4320af.zip |
Merge pull request #7225 from rails/eager_load
Improve eager load on Rails
Diffstat (limited to 'railties/lib/rails/application')
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 18 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 20 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 6 |
3 files changed, 23 insertions, 21 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index e567df7162..a1bc95550b 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -13,11 +13,18 @@ module Rails require "active_support/all" unless config.active_support.bare end - # Preload all frameworks specified by the Configuration#frameworks. - # Used by Passenger to ensure everything's loaded before forking and - # to avoid autoload race conditions in JRuby. - initializer :preload_frameworks, :group => :all do - ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks + initializer :set_eager_load, :group => :all do + if config.eager_load.nil? + warn <<-INFO +config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly: + + * development - set it to false + * test - set it to false (unless you use a tool that preloads your test environment) + * production - set it to true + +INFO + config.eager_load = config.cache_classes + end end # Initialize the logger early in the stack in case we need to log some deprecation. @@ -60,7 +67,6 @@ module Rails end # Sets the dependency loading mechanism. - # TODO: Remove files from the $" and always use require. initializer :initialize_dependency_mechanism, :group => :all do ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 2b36cc9d0d..7f05b2e7e1 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -5,11 +5,11 @@ require 'rails/engine/configuration' module Rails class Application class Configuration < ::Rails::Engine::Configuration - attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :autoflush_log, + attr_accessor :asset_host, :asset_path, :assets, :autoflush_log, :cache_classes, :cache_store, :consider_all_requests_local, :console, - :dependency_loading, :exceptions_app, :file_watcher, :filter_parameters, + :eager_load, :exceptions_app, :file_watcher, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, - :preload_frameworks, :railties_order, :relative_url_root, :secret_token, + :railties_order, :relative_url_root, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, :queue, :queue_consumer @@ -20,11 +20,9 @@ module Rails def initialize(*) super self.encoding = "utf-8" - @allow_concurrency = false @consider_all_requests_local = false @filter_parameters = [] @helpers_paths = [] - @dependency_loading = true @serve_static_assets = true @static_cache_control = nil @force_ssl = false @@ -45,6 +43,7 @@ module Rails @log_formatter = ActiveSupport::Logger::SimpleFormatter.new @queue = Rails::Queueing::Queue @queue_consumer = Rails::Queueing::ThreadedConsumer + @eager_load = nil @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false @@ -91,15 +90,12 @@ module Rails 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! - @preload_frameworks = true + 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 - @dependency_loading = false - @allow_concurrency = true + @eager_load = true self end diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 60aa40b92f..1952a0fc3a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -50,9 +50,9 @@ module Rails end initializer :eager_load! do - if config.cache_classes && !(defined?($rails_rake_task) && $rails_rake_task) + if config.eager_load ActiveSupport.run_load_hooks(:before_eager_load, self) - eager_load! + config.eager_load_namespaces.each(&:eager_load!) end end @@ -91,7 +91,7 @@ module Rails # Disable dependency loading during request cycle initializer :disable_dependency_loading do - if config.cache_classes && !config.dependency_loading + if config.eager_load ActiveSupport::Dependencies.unhook! end end |