cainlevy
2008-Nov-29 01:51 UTC
load_association_classes can block migrations (and slow down script/runner)
Hello, I ran into a problem recently that was previously reported as ticket #802 [1]. The issue, briefly, occurs when a model definition runs a class method (such as for a plugin) that checks table information. In this case, loading the model requires the database table to already exist. Running `rake db:migrate` in staging or production (anywhere with config.cache_classes=true) will then try and eager load all application classes, quickly failing with a table-not-found sort of error. Also, the eager loading seems pretty detrimental any time Rails is booted from the console, such as via `script/runner` or `rake db:migrate`. Not only can it blow up because of an unmigrated database, but it incurs a pretty senseless performance hit for what may be a simple task. This could really hit applications that use BJ to run jobs in a full Rails environment, for example. Does anyone have ideas how Rails might be smarter about when to eager load? -Lance [1] http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/802 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2008-Nov-29 11:55 UTC
Re: load_association_classes can block migrations (and slow down script/runner)
> Also, the eager loading seems pretty detrimental any time Rails is > booted from the console, such as via `script/runner` or `rake > db:migrate`. Not only can it blow up because of an unmigrated > database, but it incurs a pretty senseless performance hit for what > may be a simple task. This could really hit applications that use BJ > to run jobs in a full Rails environment, for example. > > Does anyone have ideas how Rails might be smarter about when to eager > load?This is something that''s being worked on in edge rails at present. The goal is to move that preloading code to be as ''lazy'' as it can be. The code still needs to fire in order to allow thread safe dispatching, but there''s definitely no reason to do it for rake tasks, script/runner etc. Josh and jeremy have been hacking away on it, perhaps they have something to add?> -Lance > > [1] http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/802 > > >-- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---