Merge branch 'atomaka/bugfix/n+1' into 'master'
Fix many N+1 queries Many N+1 queries have surfaced while throwing stuff together. This takes care of them. See merge request !22
This commit is contained in:
commit
c940d1a6d3
3 changed files with 7 additions and 4 deletions
|
@ -4,7 +4,10 @@ class CommentsController < ApplicationController
|
|||
before_filter :set_subcreddit
|
||||
|
||||
def show
|
||||
@comments = @comment.subtree.arrange(order: :created_at)
|
||||
@comments = @comment
|
||||
.subtree
|
||||
.includes(:post, :user)
|
||||
.arrange(order: :created_at)
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -3,11 +3,11 @@ class PostsController < ApplicationController
|
|||
before_filter :set_subcreddit
|
||||
|
||||
def index
|
||||
@posts = Post.all
|
||||
@posts = Post.includes(:subcreddit, :user).all
|
||||
end
|
||||
|
||||
def show
|
||||
@comments = @post.comments.arrange(order: :created_at)
|
||||
@comments = @post.comments.includes(:user).arrange(order: :created_at)
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class UsersController < ApplicationController
|
||||
def show
|
||||
@user = User.friendly.find(params[:id])
|
||||
@comments = @user.comments
|
||||
@comments = @user.comments.includes(:post)
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
Loading…
Reference in a new issue