Skip to content
This repository
Browse code

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 authored
2  actionmailer/lib/action_mailer.rb
@@ -57,5 +57,3 @@ module Net
57 57
 
58 58
 autoload :MailHelper, 'action_mailer/mail_helper'
59 59
 autoload :TMail, 'action_mailer/vendor/tmail'
60  
-
61  
-ActionMailer.load_all! unless ENV['LAZY']
2  actionpack/lib/action_controller.rb
@@ -100,5 +100,3 @@ class Session
100 100
 
101 101
 autoload :HTML, 'action_controller/vendor/html-scanner'
102 102
 autoload :Rack, 'action_controller/vendor/rack'
103  
-
104  
-ActionController.load_all! unless ENV['LAZY']
2  actionpack/lib/action_view.rb
@@ -55,5 +55,3 @@ class ERB
55 55
 end
56 56
 
57 57
 I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
58  
-
59  
-ActionView.load_all! unless ENV['LAZY']
2  activerecord/lib/active_record.rb
@@ -75,5 +75,3 @@ module ConnectionAdapters
75 75
 
76 76
 require 'active_record/i18n_interpolation_deprecation'
77 77
 I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
78  
-
79  
-ActiveRecord.load_all! unless ENV['LAZY']
2  activesupport/lib/active_support.rb
@@ -55,5 +55,3 @@ def self.load_all!
55 55
 require 'active_support/json'
56 56
 
57 57
 I18n.load_path << "#{File.dirname(__FILE__)}/active_support/locale/en.yml"
58  
-
59  
-ActiveSupport.load_all! unless ENV['LAZY']
2  railties/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.3.0 [Edge]*
2 2
 
  3
+* 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]
  4
+
3 5
 * Add a rake task to generate dispatchers : rake rails:generate_dispatchers [Pratik]
4 6
 
5 7
 * "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
@@ -136,6 +136,7 @@ def process
136 136
       add_gem_load_paths
137 137
 
138 138
       require_frameworks
  139
+      preload_frameworks
139 140
       set_autoload_paths
140 141
       add_plugin_load_paths
141 142
       load_environment
@@ -264,6 +265,19 @@ def require_frameworks
264 265
       raise e.to_s
265 266
     end
266 267
 
  268
+    # Preload all frameworks specified by the Configuration#frameworks.
  269
+    # Used by Passenger to ensure everything's loaded before forking and
  270
+    # to avoid autoload race conditions in JRuby.
  271
+    def preload_frameworks
  272
+      if configuration.preload_frameworks
  273
+        configuration.frameworks.each do |framework|
  274
+          # String#classify and #constantize aren't available yet.
  275
+          toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
  276
+          toplevel.load_all!
  277
+        end
  278
+      end
  279
+    end
  280
+
267 281
     # Add the load paths used by support functions such as the info controller
268 282
     def add_support_load_paths
269 283
     end
@@ -602,6 +616,9 @@ class Configuration
602 616
     # A stub for setting options on ActiveSupport.
603 617
     attr_accessor :active_support
604 618
 
  619
+    # Whether to preload all frameworks at startup.
  620
+    attr_accessor :preload_frameworks
  621
+
605 622
     # Whether or not classes should be cached (set to false if you want
606 623
     # application classes to be reloaded on each request)
607 624
     attr_accessor :cache_classes
@@ -768,6 +785,7 @@ def initialize
768 785
       self.log_level                    = default_log_level
769 786
       self.view_path                    = default_view_path
770 787
       self.controller_paths             = default_controller_paths
  788
+      self.preload_frameworks           = default_preload_frameworks
771 789
       self.cache_classes                = default_cache_classes
772 790
       self.dependency_loading           = default_dependency_loading
773 791
       self.whiny_nils                   = default_whiny_nils
@@ -810,6 +828,7 @@ def set_root_path!
810 828
     # multiple database connections. Also disables automatic dependency loading
811 829
     # after boot
812 830
     def threadsafe!
  831
+      self.preload_frameworks = true
813 832
       self.cache_classes = true
814 833
       self.dependency_loading = false
815 834
       self.action_controller.allow_concurrency = true
@@ -955,6 +974,10 @@ def default_dependency_loading
955 974
         true
956 975
       end
957 976
 
  977
+      def default_preload_frameworks
  978
+        false
  979
+      end
  980
+
958 981
       def default_cache_classes
959 982
         true
960 983
       end

0 notes on commit 104f3a5

Please sign in to comment.
Something went wrong with that request. Please try again.