render :json => {
"playlist" => playlist_description,
"songs" => @playlist.songs.as_json(:include => {:playlist_songs => {:only => [:id, :position]}})
}
上面的代碼導致1 + N查詢到數據庫,一個爲每首歌曲加載playlist_songs。 播放列表已預載入@playlist。Rails:渴望加載as_json包括
這太慢了,我該如何優化?