Luke Galea
2005-May-24 17:06 UTC
ActiveRecord - Eager updates causing prerformance problems
Hi all, I have a somewhat simple db structure with Meal and MealPlans and a has_and_belongs_to many between the two.. For some reason whenever I update the assocation (the list of meals that belong to a particular meal plan), it updates each and every meal!!! So my MealPlan model has has_and_belongs_to_many :meal The meals don''t specify anything regarding the meal_plans.. And I update by calling @meal_plan.meal.clear and then re-adding all the meals I would like to associate (ie: @meal_plan.meal << Meal.find_by_name( yada ) ) Then I call @meal_plan.save Is there a way to limit the aggresiveness of the saving?? Thanks in advance!!
Luke Galea
2005-May-26 08:29 UTC
Re: ActiveRecord - Eager updates causing prerformance problems
Just bumping my own message thread.. hoping to get some help here :( To restate my problem using more generic entities... If you have cars and people, and a mapping table to define associations between the people and cars.. Adding a car to person and saving the person should NOT result in the car itself being updated.. but that is the behavior I am seeing. Is there any way to limit the "eager assocation saving"?? Thanks in advance On Tuesday 24 May 2005 13:06, Luke Galea wrote:> Hi all, > > I have a somewhat simple db structure with Meal and MealPlans and a > has_and_belongs_to many between the two.. > > For some reason whenever I update the assocation (the list of meals that > belong to a particular meal plan), it updates each and every meal!!! > > So my MealPlan model has has_and_belongs_to_many :meal > The meals don''t specify anything regarding the meal_plans.. > > And I update by calling @meal_plan.meal.clear and then re-adding all the > meals I would like to associate (ie: @meal_plan.meal << Meal.find_by_name( > yada ) ) Then I call @meal_plan.save > > Is there a way to limit the aggresiveness of the saving?? > > Thanks in advance!! > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Dan Peterson
2005-May-26 14:10 UTC
Re: ActiveRecord - Eager updates causing prerformance problems
> Is there any way to limit the "eager assocation saving"??Have a look at this ticket: http://dev.rubyonrails.com/ticket/1343 Seems to fix what you''re talking about. Give it a try and post feedback to trac on how it works for you. -d.
Joe Van Dyk
2005-May-26 16:42 UTC
Re: ActiveRecord - Eager updates causing prerformance problems
On 5/26/05, Luke Galea <lgalea-vvW6YJTQFGvMohDmgNdYFA@public.gmane.org> wrote:> Just bumping my own message thread.. hoping to get some help here :( > > To restate my problem using more generic entities... If you have cars and > people, and a mapping table to define associations between the people and > cars.. Adding a car to person and saving the person should NOT result in the > car itself being updated.. but that is the behavior I am seeing. > > Is there any way to limit the "eager assocation saving"??Just curious, you titled this thread "Performance Problems". Are the addtional and seemingly unecessary SQL statement(s) actually a problem? Or are they a theoretical problem?> On Tuesday 24 May 2005 13:06, Luke Galea wrote: > > Hi all, > > > > I have a somewhat simple db structure with Meal and MealPlans and a > > has_and_belongs_to many between the two.. > > > > For some reason whenever I update the assocation (the list of meals that > > belong to a particular meal plan), it updates each and every meal!!! > > > > So my MealPlan model has has_and_belongs_to_many :meal > > The meals don''t specify anything regarding the meal_plans.. > > > > And I update by calling @meal_plan.meal.clear and then re-adding all the > > meals I would like to associate (ie: @meal_plan.meal << Meal.find_by_name( > > yada ) ) Then I call @meal_plan.save > > > > Is there a way to limit the aggresiveness of the saving?? > > > > Thanks in advance!! > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Luke Galea
2005-May-26 18:43 UTC
Re: ActiveRecord - Eager updates causing prerformance problems
> Just curious, you titled this thread "Performance Problems". Are the > addtional and seemingly unecessary SQL statement(s) actually a > problem? Or are they a theoretical problem?When I am running in production mode with the db on the same machine as the app, it''s all good.. But when I develop with the db on a seperate machine and have the app running on my laptop connected wirelessly.. well: performance problems are exaggerated. I like developing like that though because it lets me catch those types of problems in the development stage rather than after the app is in heavy use and the number of rows has increased to the point where we start hitting that limit.
Michael Campbell
2005-May-26 22:56 UTC
Re: ActiveRecord - Eager updates causing prerformance problems
Seems to me you''re just running into network latency there (and/or bandwidth issues with large datasets), no? On 5/26/05, Luke Galea <lgalea-vvW6YJTQFGvMohDmgNdYFA@public.gmane.org> wrote:> > Just curious, you titled this thread "Performance Problems". Are the > > addtional and seemingly unecessary SQL statement(s) actually a > > problem? Or are they a theoretical problem? > > When I am running in production mode with the db on the same machine as the > app, it''s all good.. > > But when I develop with the db on a seperate machine and have the app running > on my laptop connected wirelessly.. well: performance problems are > exaggerated. > > I like developing like that though because it lets me catch those types of > problems in the development stage rather than after the app is in heavy use > and the number of rows has increased to the point where we start hitting that > limit. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >