I''m currently working on a Rails 2.3 project but I think the code hasn''t changed much around touching in the latest release so here goes: Touching seems to be less efficient than it could be. Currently it seems to change the updated_at (or other) field, save the whole object, trigger all callbacks on that object (some of which might be to touch other associated objects) and so on. Seems to me that there could be performance gains made (especially when it comes to deleting and cloning deeply nested relational structures) by making touch only update_attribute the appropriate fields, and then only call the associated touch callbacks (because they''re already named well they can be identified) and so on. Is there a reason why it''s not does this way already? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/THT-W4w5MvsJ. 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.
On Jun 7, 2012, at 6:55 PM, Spike wrote:> I''m currently working on a Rails 2.3 project but I think the code hasn''t changed much around touching in the latest release so here goes: > > Touching seems to be less efficient than it could be. Currently it seems to change the updated_at (or other) field, save the whole object, trigger all callbacks on that object (some of which might be to touch other associated objects) and so on. > > Seems to me that there could be performance gains made (especially when it comes to deleting and cloning deeply nested relational structures) by making touch only update_attribute the appropriate fields, and then only call the associated touch callbacks (because they''re already named well they can be identified) and so on. > > Is there a reason why it''s not does this way already?The implementation in Rails 3 is entirely different: http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch It now skips all the callbacks, etc entirely. --Matt Jones -- 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.
Thanks Matt, sorry I missed this reply. Bummer I''m still on 2.3, will have to get moving on the upgrade :D Cheers, Brendon On Friday, June 8, 2012 12:30:02 PM UTC+12, Matt jones wrote:> > > On Jun 7, 2012, at 6:55 PM, Spike wrote: > > > I''m currently working on a Rails 2.3 project but I think the code hasn''t > changed much around touching in the latest release so here goes: > > > > Touching seems to be less efficient than it could be. Currently it seems > to change the updated_at (or other) field, save the whole object, trigger > all callbacks on that object (some of which might be to touch other > associated objects) and so on. > > > > Seems to me that there could be performance gains made (especially when > it comes to deleting and cloning deeply nested relational structures) by > making touch only update_attribute the appropriate fields, and then only > call the associated touch callbacks (because they''re already named well > they can be identified) and so on. > > > > Is there a reason why it''s not does this way already? > > The implementation in Rails 3 is entirely different: > > > http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch > > It now skips all the callbacks, etc entirely. > > --Matt Jones-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/LuYQHWivEd4J. 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.