RailsCasts中文版,#22 Eager Loading 贪婪加载(级连查询)
要想试图优化你的Rails应用,首先应当把目光投向数据库访问操作。减少对数据库的访问次数能对应用的运行效率产生巨大的提升作用。下面来介绍一种叫做贪婪读取的技术
@tasks = Task.find(:all, :include => [:project, {:comments => :user }])
使用贪婪加载可以通过减少数据库访问次数提高应用的性能。更多信息可以到Rails的API文档中去了解。http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
作者授权:Your welcome to post the translated text on your blog as well if the episode is free(not Pro). I just ask that you post a link back to the original episode on railscasts.com.
原文链接:http://railscasts.com/episodes/22-eager-loading