Skip to content

Commit

Permalink
Merge pull request #3632 from shibaaaa/turning_question_index
Browse files Browse the repository at this point in the history
質問一覧画面で発生していたN+1を解消
  • Loading branch information
komagata authored Nov 29, 2021
2 parents 4352d91 + 4c503ec commit bd0f2a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ def index
else
Question.not_solved
end
@tag = params[:tag]
@tags = questions.all_tags
questions = params[:practice_id].present? ? questions.where(practice_id: params[:practice_id]) : questions
questions = questions.tagged_with(params[:tag]) if params[:tag]
questions = questions.includes(:practice, :answers).order(updated_at: :desc, id: :desc)
@questions = questions.with_avatar.page(params[:page])
@questions = questions
.with_avatar
.includes(:practice, :answers, :tags, :correct_answer, user: :company)
.order(updated_at: :desc, id: :desc)
.page(params[:page])
@questions_property = questions_property
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/questions/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ header.page-header
#js-practice-select data-solved=params[:solved] data-current-user-id=current_user.id
= render 'questions/tabs'

- if @tag.present?
- if params[:tag].present?
header.page-main-header
.container
.page-main-header__inner
.page-main-header__start
h1.page-main-header__title
| タグ「#{@tag}」のQ&A(#{@questions.total_count}
| タグ「#{params[:tag]}」のQ&A(#{@questions.total_count}
.page-body
.container.is-lg
= paginate @questions
Expand Down

0 comments on commit bd0f2a5

Please sign in to comment.