Rolf Timmermans
2010-Jun-27 12:26 UTC
Column definitions not cached for calculations on has_many association with :include
Hi everyone, While trying out Rails 3 for one of my applications, I have been bitten by the following. When doing a calculation such as .count on has_many associations that use :include => some_model, it appears column definitions are not cached. It''s not cached when config.cache_classes = true, or even in the same request. This causes pretty serious performance issues, because retrieving column definitions this often is expensive. A short example: class Article < ActiveRecord::Base has_many :comments, :include => :author end class Comment < ActiveRecord::Base belongs_to :author end class Author < ActiveRecord::Base end Article.last.comments.count # Retrieves column definitions from db every single time. Attached to this e-mail is a patch with a failing test. I don''t know if there are other kinds of queries that suffer from the same problem. I would also be happy to write a patch that fixes the problem, but so far I''m having trouble understanding where the responsibility of caching the column definitions should be exactly (or even figuring out where the column definitions are cached right now). Any help or suggestions on how to tackle this problem are most welcome. Thank you! Kind regards, Rolf Timmermans -- 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
2010-Jun-28 02:00 UTC
Re: Column definitions not cached for calculations on has_many association with :include
> Attached to this e-mail is a patch with a failing test. I don''t know if there are other kinds of queries that suffer from the same problem.Could you open a lighthouse ticket with this please? We''ll need it in there to make sure we don''t miss it for 3.0 final. -- 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.
Rolf Timmermans
2010-Jun-28 07:27 UTC
Re: Column definitions not cached for calculations on has_many association with :include
On Jun 28, 2010, at 4:00 , Michael Koziarski wrote:>> Attached to this e-mail is a patch with a failing test. I don''t know if there are other kinds of queries that suffer from the same problem. > > Could you open a lighthouse ticket with this please? We''ll need it in > there to make sure we don''t miss it for 3.0 final. >Sure, a ticket has been created (https://rails.lighthouseapp.com/projects/8994/tickets/4991). In the mean time I also found out that the same problem occurs when using joins(), e.g. Articles.joins(:comments).all. This time it happens even with has_many associations without :include. Kind regards, Rolf Timmermans -- 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.