Skip to content

Commit

Permalink
Ensure user profiles and questions are eager loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
raccube committed Oct 22, 2023
1 parent 2432010 commit dd31a70
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UserController < ApplicationController
after_action :mark_notification_as_read, only: %i[show]

def show
@pinned_answers = @user.answers.pinned.order(pinned_at: :desc).limit(10)
@pinned_answers = @user.answers.pinned.includes([{user: :profile}, :question]).order(pinned_at: :desc).limit(10)
paginate_answers { |args| @user.cursored_answers(**args) }

respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/models/answer/timeline_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Answer::TimelineMethods
define_cursor_paginator :cursored_public_timeline, :public_timeline

def public_timeline(current_user: nil)
joins(:user)
includes([{user: :profile}, :question])
.then do |query|
next query unless current_user

Expand Down
3 changes: 2 additions & 1 deletion app/models/list/timeline_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module List::TimelineMethods

define_cursor_paginator :cursored_timeline, :timeline

# @return [Array] the lists' timeline
# @return [ActiveRecord::Relation<Answer>] the lists' timeline
def timeline(current_user: nil)
Answer
.includes([{user: :profile}, :question])
.then do |query|
next query unless current_user

Expand Down
1 change: 1 addition & 0 deletions app/models/question/answer_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Question::AnswerMethods

def ordered_answers(current_user: nil)
answers
.includes([{user: :profile}, :question])
.then do |query|
next query unless current_user

Expand Down

0 comments on commit dd31a70

Please sign in to comment.