From ff8035dfeed8c86594c32ef8e9204806e190cb58 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 7 Aug 2016 17:09:29 +0200 Subject: Defer requiring Rake until it's needed. Eagerly requiring Rake could put 100ms on to the Rails boot time. Shimmy that down to 0 by requiring Rake when no native Rails command exists and we try to run a Rake task. Or when printing all the Rake commands through `rails help`. Fixes #25029 --- railties/lib/rails/commands/rake_proxy.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/rake_proxy.rb b/railties/lib/rails/commands/rake_proxy.rb index ad5249ff48..b9e50f3e5a 100644 --- a/railties/lib/rails/commands/rake_proxy.rb +++ b/railties/lib/rails/commands/rake_proxy.rb @@ -1,10 +1,11 @@ -require "rake" require "active_support" module Rails module RakeProxy #:nodoc: private def run_rake_task(command) + require_rake + ARGV.unshift(command) # Prepend the command, so Rake knows how to run it. Rake.application.standard_exception_handling do @@ -15,6 +16,8 @@ module Rails end def rake_tasks + require_rake + return @rake_tasks if defined?(@rake_tasks) ActiveSupport::Deprecation.silence do @@ -30,5 +33,9 @@ module Rails def formatted_rake_tasks rake_tasks.map { |t| [ t.name_with_args, t.comment ] } end + + def require_rake + require "rake" # Defer booting Rake until we know it's needed. + end end end -- cgit v1.2.3