~cytrogen/gstack

ref: c620de38e19fe63e8a6e361e11d706b5ed432b93 gstack/test/fixtures/review-army-n-plus-one.rb -rw-r--r-- 313 bytes
c620de38 — Garry Tan fix: setup runs pending migrations so git pull + ./setup works (#774) 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
# N+1 query example — intentionally bad for testing
class PostsController
  def index
    @posts = Post.all
    @posts.each do |post|
      # N+1: queries Author table for every post
      puts post.author.name
      # N+1: queries Comments table for every post
      puts post.comments.count
    end
  end
end