Ensure user profiles and questions are eager loaded

This commit is contained in:
Karina Kwiatek 2023-10-22 19:51:23 +02:00
parent 2432010256
commit 491fb359d2
4 changed files with 5 additions and 3 deletions

View file

@ -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|

View file

@ -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

View file

@ -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

View file

@ -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