it’s my first question in stackoverflow.
In my application i have a real time section, to see the movements of the web. Its an online newspaper and ths section shows: new article, new comment, new vote, new debate…..all what is happening on the web.
I have this code:
def index
@objects = Article.find(:all, :conditions => { :created_at => (Time.now-48.hours)..(Time.now), :published => true })
@objects = @objects + Debate.find(:all, :conditions => { :created_at => (Time.now-48.hours)..(Time.now), :active => true })
@objects = @objects + Event.find(:all, :conditions => { :created_at => (Time.now-48.hours)..(Time.now), :active => true })
@objects = @objects + Comment.find(:all, :conditions => { :created_at => (Time.now-48.hours)..(Time.now), :active => true })
@objects = @objects + Vote.find(:all, :conditions => { :created_at => (Time.now-48.hours)..(Time.now) })
@objects.sort! {|x,z| x.created_at <=> z.created_at}
@objects.reverse!
end
I load all in the last 48 hours. I’ve been reading about caching in rails because I think that this isn’t my solution.
What can I do to load this list more fast? Because now it takes 7…or 8 seconds…
Thanks for all 😀
few notes:
find(:all)is deprecated. usewhere()instead.y <=> xso it will sort the way you need.hope it helps..