aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-11-24 18:43:04 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2008-11-24 18:43:04 -0800
commit104f3a57768602289299b3be0fab5b1ed21d7653 (patch)
tree8e467393ec0541d3db1cacd895e094e995574eb4
parentd01f75b1f091c37d14ece70cbe5f52f20f25d64c (diff)
downloadrails-104f3a57768602289299b3be0fab5b1ed21d7653.tar.gz
rails-104f3a57768602289299b3be0fab5b1ed21d7653.tar.bz2
rails-104f3a57768602289299b3be0fab5b1ed21d7653.zip
Add config.preload_frameworks to load all frameworks at startup. Default to false so Rails autoloads itself as it's used.
-rw-r--r--actionmailer/lib/action_mailer.rb2
-rw-r--r--actionpack/lib/action_controller.rb2
-rw-r--r--actionpack/lib/action_view.rb2
-rw-r--r--activerecord/lib/active_record.rb2
-rw-r--r--activesupport/lib/active_support.rb2
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/initializer.rb23
7 files changed, 25 insertions, 10 deletions
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb
index dbb3fae13a..b4693b192b 100644
--- a/actionmailer/lib/action_mailer.rb
+++ b/actionmailer/lib/action_mailer.rb
@@ -57,5 +57,3 @@ end
autoload :MailHelper, 'action_mailer/mail_helper'
autoload :TMail, 'action_mailer/vendor/tmail'
-
-ActionMailer.load_all! unless ENV['LAZY']
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 08e6f4efa8..62d75a47ec 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -100,5 +100,3 @@ autoload :Mime, 'action_controller/mime_type'
autoload :HTML, 'action_controller/vendor/html-scanner'
autoload :Rack, 'action_controller/vendor/rack'
-
-ActionController.load_all! unless ENV['LAZY']
diff --git a/actionpack/lib/action_view.rb b/actionpack/lib/action_view.rb
index 436bce4a69..210a5f1a93 100644
--- a/actionpack/lib/action_view.rb
+++ b/actionpack/lib/action_view.rb
@@ -55,5 +55,3 @@ class ERB
end
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
-
-ActionView.load_all! unless ENV['LAZY']
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 55f06ed832..348e5b94af 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -75,5 +75,3 @@ end
require 'active_record/i18n_interpolation_deprecation'
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
-
-ActiveRecord.load_all! unless ENV['LAZY']
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index e64771033c..3758f63eb0 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -55,5 +55,3 @@ require 'active_support/core_ext'
require 'active_support/json'
I18n.load_path << "#{File.dirname(__FILE__)}/active_support/locale/en.yml"
-
-ActiveSupport.load_all! unless ENV['LAZY']
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index a586940f22..41aedaeb1e 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -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]
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 82b7b604ae..0f74f9ff88 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -136,6 +136,7 @@ module Rails
add_gem_load_paths
require_frameworks
+ preload_frameworks
set_autoload_paths
add_plugin_load_paths
load_environment
@@ -264,6 +265,19 @@ module Rails
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 @@ Run `rake gems:install` to install the missing gems.
# 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 @@ Run `rake gems:install` to install the missing gems.
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 @@ Run `rake gems:install` to install the missing gems.
# 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 @@ Run `rake gems:install` to install the missing gems.
true
end
+ def default_preload_frameworks
+ false
+ end
+
def default_cache_classes
true
end