Skip to content
This repository
Browse code

Speed up boot by tsorting as infrequently as possible

  • Loading branch information...
commit cdb8609c64ed7db7ea91cdcd4bcb4b400f7dfe07 1 parent 60ab925
Jeremy Kemper jeremy authored
2  railties/lib/rails/application.rb
@@ -178,7 +178,7 @@ def initializers
178 178 railties.all { |r| initializers += r.initializers }
179 179 initializers += super
180 180 initializers += Finisher.initializers_for(self)
181   - initializers
  181 + Collection.new(initializers)
182 182 end
183 183
184 184 protected
9 railties/lib/rails/initializable.rb
@@ -39,11 +39,6 @@ def tsort_each_child(initializer, &block)
39 39 select { |i| i.before == initializer.name || i.name == initializer.after }.each(&block)
40 40 end
41 41
42   - def initialize(initializers = [])
43   - super(initializers)
44   - replace(tsort)
45   - end
46   -
47 42 def +(other)
48 43 Collection.new(to_a + other.to_a)
49 44 end
@@ -51,7 +46,7 @@ def +(other)
51 46
52 47 def run_initializers(*args)
53 48 return if instance_variable_defined?(:@ran)
54   - initializers.each do |initializer|
  49 + initializers.tsort.each do |initializer|
55 50 initializer.run(*args)
56 51 end
57 52 @ran = true
@@ -94,4 +89,4 @@ def run_initializers(*args)
94 89 end
95 90 end
96 91 end
97   -end
  92 +end
2  railties/test/railties/engine_test.rb
@@ -41,7 +41,7 @@ class Engine < ::Rails::Engine
41 41
42 42 boot_rails
43 43
44   - initializers = Rails.application.initializers
  44 + initializers = Rails.application.initializers.tsort
45 45 index = initializers.index { |i| i.name == "dummy_initializer" }
46 46 selection = initializers[(index-3)..(index)].map(&:name).map(&:to_s)
47 47

0 comments on commit cdb8609

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