Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure user profiles and questions are eager loaded #1407

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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