0
這是我在stackoverflow中的第一個問題。Rails將一些列表ob對象加載到緩存中
在我的應用程序中,我有一個實時部分,以查看網絡的運動。它的一個在線報紙和這一節顯示:新文章,新評論,新投票,新辯論.....所有在網上發生的事情。
我有這樣的代碼:
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
我加載所有在過去48小時。我一直在閱讀有關緩存的問題,因爲我認爲這不是我的解決方案。
我能做些什麼來加載這個列表更快?因爲現在需要7 ...秒或8秒......
感謝所有:d
好吧! 1解決了。我用在哪裏。在步驟2中,通過db連接,我無法想象如何在一個連接中完成所有連接,因爲有5個模型。我是新來的...抱歉...... – pekpon