I was hoping that the Rails'' QueryCache might cache the ActiveRecord objects it creates and not just the SQL result set, but some experimentation shows that this is not the case. For example:>> ActiveRecord::Base.cache do?> u = User.find(:first)>> u.name="z" >> u = User.find(:first) >> endreturns a clean copy of the object. My question is, is there a way to cache the ActiveRecord objects as well? I have read that their construction is time consuming. I found the plugin ActiveRecordContext (http://github.com/dcadenas/ active_record_context) but it was last updated *way* back in 2007, so I wasn''t sure it is the best thing to use (or if it even works with the current Rails). Thanks, --Paul -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > My question is, is there a way to cache the ActiveRecord objects as > well? I have read that their construction is time consuming.I think that used to be the case, but I don''t think it is any more (which may be why the Query cache doesn''t cache them). Also, how many objects are you constructing? It should really only be a page worth, otherwise I''d use aggregate functions (if you''re just iterating anyway). Cheers, Andy -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for the reply. I''m not sure about how many objects, but for page (on which we are showing way, way too much information) we do about 5000 SQL queries, a few of which might pull back 100 records or so. I think a lot of those calls could be collapsed with eager loading. But, lets say there are 6000 objects. On my system, I calculated the object construction time (not including SQL time) as being .000031s, which for 6000 objects adds up to 0.186s-- which is not insignificant, though probably not our biggest performance issue. I took a look at aggregate functions, and I don''t think they would be of much use in this case, but thanks for mentioning them because I wasn''t aware you could do that. --Paul On Feb 24, 6:05 am, Andy Jeffries <andyjeffr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > My question is, is there a way to cache the ActiveRecord objects as > > well? I have read that their construction is time consuming. > > I think that used to be the case, but I don''t think it is any more (which > may be why the Query cache doesn''t cache them). Also, how many objects are > you constructing? It should really only be a page worth, otherwise I''d use > aggregate functions (if you''re just iterating anyway). > > Cheers, > > Andy-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Wow!!! 5000 SQL queries! I don''t know what you''re doing, but I hope you''re not allowing lots of people to view that page at the same time, MySQL meltdown ;-) Cheers, Andy -- Andy Jeffries http://andyjeffries.co.uk/ #rubyonrails #mysql #jquery Registered address: 64 Sish Lane, Stevenage, Herts, SG1 3LS Company number: 5452840 On 24 February 2010 16:41, Paul E. G. Lynch <plynchnlm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I''m not sure about how many objects, but for > page (on which we are showing way, way too much information) we do > about 5000 SQL queries, a few of which might pull back 100 records or > so. I think a lot of those calls could be collapsed with eager > loading. But, lets say there are 6000 objects. On my system, I > calculated the object construction time (not including SQL time) as > being .000031s, which for 6000 objects adds up to 0.186s-- which is > not insignificant, though probably not our biggest performance issue. > > I took a look at aggregate functions, and I don''t think they would be > of much use in this case, but thanks for mentioning them because I > wasn''t aware you could do that. > > --Paul > > On Feb 24, 6:05 am, Andy Jeffries <andyjeffr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > My question is, is there a way to cache the ActiveRecord objects as > > > well? I have read that their construction is time consuming. > > > > I think that used to be the case, but I don''t think it is any more (which > > may be why the Query cache doesn''t cache them). Also, how many objects > are > > you constructing? It should really only be a page worth, otherwise I''d > use > > aggregate functions (if you''re just iterating anyway). > > > > Cheers, > > > > Andy > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.