我經常遇到這種情況。將ActiveRecord從已經緩存的內容獲取到查詢
post_comments = post.comments
#grabs maybe 3 records out of thousands in the table
do_something_with post_comments
#...later in the same request...
subset_of_comments = post_comments.where(:awesome=>true)
#hits the database again :-(
do_something_else subset_of_comments
我認識到數據庫在查找記錄非常好,但我不明白怎麼回事回滿了桌子和期待通過成千上萬的記錄是不是搜索小的記錄集連接到這更好已經爲我需要的1或2個緩存了。
如果我想提高此過程的效率,該怎麼辦?
不正確的!這不會返回post_comments的子集。只是一個布爾值數組。 – atmaish
你是對的,我只是改變了發現地圖,並忘記糾正塊 –
謝謝,這是相當明顯,實際上。出於某種原因,我對使用ruby枚舉函數有一個心理障礙。我想我只是覺得這很酷,如果ActiveRecord記得我之前是否在其他地方完成過濾。 – pseudopeach