Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

unnecessarily loading environment

#1539

misc.rake in task :environment often unneccessarily loads the environment after it's already been loaded. This causes most rake tasks to run quite a bit slower.

The solution: require environment unless defined?(Rails)

Reported by Steven Soroka · December 9th, 2008 @ 07:39 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Steven Soroka
    Steven Soroka

    I found this by putting print "loading environment" at the top of config/environment.rb

    Wondering if anyone can confirm that rake tasks are loading the environment multiple times.

    January 9th, 2009 @ 10:48 PM

  2. Chris Kampmeier
    Chris Kampmeier

    I can't seem to confirm this.

    I generated a fresh Rails app from rails/master (at 296ca4da1700eb27a7043112d22027444ea0e548), and vendor'd rails. I stuck a puts in environment.rb, and all rake tasks that required the environment only seemed to print it once:

    chrisk@al3:~/Documents/railstest/testapp $ rake db:version
    (in /Users/chrisk/Documents/railstest/testapp)
    *** initializing Rails
    Current version: 0
    chrisk@al3:~/Documents/railstest/testapp $ 
    
    

    Also, the whole point of require is that it'll only load a file once... Kernel#load is the one that mindlessly loads things again when you specify it twice.

    So, can you post a step-by-step process to reproduce? We must be doing something different.

    Thanks!

    January 12th, 2009 @ 05:33 AM

  3. Steven Soroka
    Steven Soroka

    require will load the same library twice if you provide a different path to the same file, eg, require 'config/environment' and require "#{RAILS_ROOT}/config/environment"

    Though I duplicated your setup with a fresh install and couldn't replicate the problem. I'll try to isolate it in my project and see what's happening.

    January 12th, 2009 @ 02:54 PM

  4. Steven Soroka
    Steven Soroka

    I found an environment require in a task I didn't need, and the rest of the duplicate loads are related to rspec, so I'll just close this ticket.

    January 12th, 2009 @ 04:27 PM

  5. Pratik
    Pratik
    • State changed from new to invalid

    March 12th, 2009 @ 05:24 PM