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 <asitkmis...@gmail.com>:
> 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...@gmail.com> 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...@gmail.com> 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-t...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > rubyonrails-talk+unsubscr...@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-t...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> rubyonrails-talk+unsubscr...@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-t...@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to