What''s the best way to handle views that show the top 10/most popular/ Recently updated/most commented type listing? Should I have a separate model that is populated with records from other models by a background job or should I need to use some sort of caching? Perhaps both? Thanks! -- 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.
Check out the :counter_cache option of belongs_to. If you order by that and limit to 10, you''ll probably have what you''re after. /Ritchie On May 25, 12:42 am, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What''s the best way to handle views that show the top 10/most popular/ > Recently updated/most commented type listing? > > Should I have a separate model that is populated with records from > other models by a background job or should I need to use some sort of > caching? Perhaps both? > > Thanks! > > -- > 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 athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks! Let me clarify. On my home page, I would like to show the following top 10 clubs in your area most popular comments in your area popular events in your area.. . . and so on. This view will essentially show 10-15 records from 7-8 models. Which is a lot of queries and of course, its the home page, which I wanna make sure loads fast. What''s the best way to optimize it? Should I have another model called popular with colums names such as popular_events, popular_clubs, etc and populate/depopulate that with a background job? or is there a better way? Thanks On May 24, 6:06 pm, Ritchie <ritch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Check out the :counter_cache option of belongs_to. If you order by > that and limit to 10, you''ll probably have what you''re after. > > /Ritchie > > On May 25, 12:42 am, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What''s the best way to handle views that show the top 10/most popular/ > > Recently updated/most commented type listing? > > > Should I have a separate model that is populated with records from > > other models by a background job or should I need to use some sort of > > caching? Perhaps both? > > > Thanks! > > > -- > > 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 athttp://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@googlegroups.com. > For more options, visit this group athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Folks, any thoughts? On May 24, 7:15 pm, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks! > > Let me clarify. > > On my home page, I would like to show the following > > top 10 clubs in your area > most popular comments in your area > popular events in your area.. > . > . > and so on. > > This view will essentially show 10-15 records from 7-8 models. Which > is a lot of queries and of course, its the home page, which I wanna > make sure loads fast. > > What''s the best way to optimize it? > > Should I have another model called popular with colums names such as > popular_events, popular_clubs, etc and populate/depopulate that with a > background job? or is there a better way? > > Thanks > > On May 24, 6:06 pm, Ritchie <ritch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Check out the :counter_cache option of belongs_to. If you order by > > that and limit to 10, you''ll probably have what you''re after. > > > /Ritchie > > > On May 25, 12:42 am, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > What''s the best way to handle views that show the top 10/most popular/ > > > Recently updated/most commented type listing? > > > > Should I have a separate model that is populated with records from > > > other models by a background job or should I need to use some sort of > > > caching? Perhaps both? > > > > Thanks! > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://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 athttp://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@googlegroups.com. > For more options, visit this group athttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 May 2010 03:15, badnaam <asitkmishra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks! > > Let me clarify. > > On my home page, I would like to show the following > > top 10 clubs in your area > most popular comments in your area > popular events in your area.. > . > . > and so on. > > This view will essentially show 10-15 records from 7-8 models. Which > is a lot of queries and of course, its the home page, which I wanna > make sure loads fast. > > What''s the best way to optimize it?I would not worry about optimising it until it becomes clear that it is going to be a problem. It is generally true that the bottlenecks in an app are not where you expect them to be. Optimising before you know exactly where the issues are is a waste of time. Make sure you have full test coverage so that when (if) you need to refactor you can be confident that all is still working. Colin> > Should I have another model called popular with colums names such as > popular_events, popular_clubs, etc and populate/depopulate that with a > background job? or is there a better way? > > Thanks > > > On May 24, 6:06 pm, Ritchie <ritch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Check out the :counter_cache option of belongs_to. If you order by >> that and limit to 10, you''ll probably have what you''re after. >> >> /Ritchie >> >> On May 25, 12:42 am, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > What''s the best way to handle views that show the top 10/most popular/ >> > Recently updated/most commented type listing? >> >> > Should I have a separate model that is populated with records from >> > other models by a background job or should I need to use some sort of >> > caching? Perhaps both? >> >> > Thanks! >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFFw@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 athttp://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 athttp://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@googlegroups.com. > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can also have a background job that queries all models for top 10 results and save them into top_10 table. This job may refresh the top_10 table once a day for example (late at night?). This way your home page should not perform a lot of expensive queries for each visitor. As Colin Law said optimization should be done when it becomes necessary. regards 2010/5/25 badnaam <asitkmishra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Thanks! > > Let me clarify. > > On my home page, I would like to show the following > > top 10 clubs in your area > most popular comments in your area > popular events in your area.. > . > . > and so on. > > This view will essentially show 10-15 records from 7-8 models. Which > is a lot of queries and of course, its the home page, which I wanna > make sure loads fast. > > What''s the best way to optimize it? > > Should I have another model called popular with colums names such as > popular_events, popular_clubs, etc and populate/depopulate that with a > background job? or is there a better way? > > Thanks > > > On May 24, 6:06 pm, Ritchie <ritch...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Check out the :counter_cache option of belongs_to. If you order by >> that and limit to 10, you''ll probably have what you''re after. >> >> /Ritchie >> >> On May 25, 12:42 am, badnaam <asitkmis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > What''s the best way to handle views that show the top 10/most popular/ >> > Recently updated/most commented type listing? >> >> > Should I have a separate model that is populated with records from >> > other models by a background job or should I need to use some sort of >> > caching? Perhaps both? >> >> > Thanks! >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFFw@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 athttp://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 athttp://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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------ Oliver Hernàndez Valls http://codit.wikidot.com http://wiki.tramuntanal.cat -- 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.