Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add config.preload_frameworks to load all frameworks at startup. Defa…

…ult to false so Rails autoloads itself as it's used.
  • Loading branch information...
commit 104f3a57768602289299b3be0fab5b1ed21d7653 1 parent d01f75b
Jeremy Kemper jeremy authored
2  actionmailer/lib/action_mailer.rb
View
@@ -57,5 +57,3 @@ module Net
autoload :MailHelper, 'action_mailer/mail_helper'
autoload :TMail, 'action_mailer/vendor/tmail'
-
-ActionMailer.load_all! unless ENV['LAZY']
2  actionpack/lib/action_controller.rb
View
@@ -100,5 +100,3 @@ class Session
autoload :HTML, 'action_controller/vendor/html-scanner'
autoload :Rack, 'action_controller/vendor/rack'
-
-ActionController.load_all! unless ENV['LAZY']
2  actionpack/lib/action_view.rb
View
@@ -55,5 +55,3 @@ class ERB
end
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
-
-ActionView.load_all! unless ENV['LAZY']
2  activerecord/lib/active_record.rb
View
@@ -75,5 +75,3 @@ module ConnectionAdapters
require 'active_record/i18n_interpolation_deprecation'
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
-
-ActiveRecord.load_all! unless ENV['LAZY']
2  activesupport/lib/active_support.rb
View
@@ -55,5 +55,3 @@ def self.load_all!
require 'active_support/json'
I18n.load_path << "#{File.dirname(__FILE__)}/active_support/locale/en.yml"
-
-ActiveSupport.load_all! unless ENV['LAZY']
2  railties/CHANGELOG
View
@@ -1,5 +1,7 @@
*2.3.0 [Edge]*
+* Add config.preload_frameworks to load all frameworks at startup. Default to false so Rails autoloads itself as it's used. Turn this on for Passenger and JRuby. Also turned on by config.threadsafe! [Jeremy Kemper]
+
* Add a rake task to generate dispatchers : rake rails:generate_dispatchers [Pratik]
* "rails <app>" will not generate public/dispatch.cgi/fcgi/rb files by default now. Please use "--with-dispatchers" option if you need them. [Yaroslav Markin, Pratik Naik]
23 railties/lib/initializer.rb
View
@@ -136,6 +136,7 @@ def process
add_gem_load_paths
require_frameworks
+ preload_frameworks
set_autoload_paths
add_plugin_load_paths
load_environment
@@ -264,6 +265,19 @@ def require_frameworks
raise e.to_s
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.
+ def preload_frameworks
+ if configuration.preload_frameworks
+ configuration.frameworks.each do |framework|
+ # String#classify and #constantize aren't available yet.
+ toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
+ toplevel.load_all!
+ end
+ end
+ end
+
# Add the load paths used by support functions such as the info controller
def add_support_load_paths
end
@@ -602,6 +616,9 @@ class Configuration
# A stub for setting options on ActiveSupport.
attr_accessor :active_support
+ # Whether to preload all frameworks at startup.
+ attr_accessor :preload_frameworks
+
# Whether or not classes should be cached (set to false if you want
# application classes to be reloaded on each request)
attr_accessor :cache_classes
@@ -768,6 +785,7 @@ def initialize
self.log_level = default_log_level
self.view_path = default_view_path
self.controller_paths = default_controller_paths
+ self.preload_frameworks = default_preload_frameworks
self.cache_classes = default_cache_classes
self.dependency_loading = default_dependency_loading
self.whiny_nils = default_whiny_nils
@@ -810,6 +828,7 @@ def set_root_path!
# multiple database connections. Also disables automatic dependency loading
# after boot
def threadsafe!
+ self.preload_frameworks = true
self.cache_classes = true
self.dependency_loading = false
self.action_controller.allow_concurrency = true
@@ -955,6 +974,10 @@ def default_dependency_loading
true
end
+ def default_preload_frameworks
+ false
+ end
+
def default_cache_classes
true
end
Please sign in to comment.
Something went wrong with that request. Please try again.