|
|
|
|
|
by shafqat
6331 days ago
|
|
Can someone shed some extra light about the point re: reducing the number of requests to the DB for a dynamic page. When left unoptimized, Rails (and a lot of other frameworks) often result in 100 DB queries for a page. One obvious way around this is to ensure the DB joins are done correctly. But the article mentions batching/grouping up the requests. How does that work? |
|
Say you have 30 blog posts, and your views reference associations to the blog post's owners. Well, views are dumb and if you call post.user on each one within a loop, you end up calling User.find 30 times.
But if you do Post.find(..., :include => [:user]), Rails will know to eager load all users -- and User.find never gets called 10 times.