2011-08-02 69 views
0

以下查詢在heroku中製造麻煩。響應時間太長,有時會導致應用程序錯誤,因爲heroku具有30秒的超時限制。任何幫助將不勝感激。activerecord性能問題

@entries = Entry.where(:created_at => Time.now-2.day..Time.now).joins("left join training_entries on training_entries.entry_id = entries.id").where(:training_entries => { :entry_id => nil}).order('entries.created_at DESC') 



    ←[1m←[36mEntry Load (523.0ms)←[0m ←[1mSELECT `entries`.* FROM `entries` left join training_entries on training_entries.entry_id 
= entries.id WHERE `training_entries`.`entry_id` IS NULL 
AND (`entries`.`created_at` BETWEEN '2011-07-31 21:00:00' AND '2011-08-02 21:00:00') ORDER BY entries.created_at DESC LIMIT 1 
0 OFFSET 0←[0m 
+0

你可以發佈由此產生的SQL嗎? –

回答

2
  • 指數training_entriescreated_atentries
  • 指數entry_id列。
+0

完全是我的想法! – rubish