Ensure user profiles and questions are eager loaded
This commit is contained in:
parent
2432010256
commit
491fb359d2
|
@ -8,7 +8,7 @@ class UserController < ApplicationController
|
||||||
after_action :mark_notification_as_read, only: %i[show]
|
after_action :mark_notification_as_read, only: %i[show]
|
||||||
|
|
||||||
def 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) }
|
paginate_answers { |args| @user.cursored_answers(**args) }
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Answer::TimelineMethods
|
||||||
define_cursor_paginator :cursored_public_timeline, :public_timeline
|
define_cursor_paginator :cursored_public_timeline, :public_timeline
|
||||||
|
|
||||||
def public_timeline(current_user: nil)
|
def public_timeline(current_user: nil)
|
||||||
joins(:user)
|
includes([{ user: :profile }, :question])
|
||||||
.then do |query|
|
.then do |query|
|
||||||
next query unless current_user
|
next query unless current_user
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,10 @@ module List::TimelineMethods
|
||||||
|
|
||||||
define_cursor_paginator :cursored_timeline, :timeline
|
define_cursor_paginator :cursored_timeline, :timeline
|
||||||
|
|
||||||
# @return [Array] the lists' timeline
|
# @return [ActiveRecord::Relation<Answer>] the lists' timeline
|
||||||
def timeline(current_user: nil)
|
def timeline(current_user: nil)
|
||||||
Answer
|
Answer
|
||||||
|
.includes([{ user: :profile }, :question])
|
||||||
.then do |query|
|
.then do |query|
|
||||||
next query unless current_user
|
next query unless current_user
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ module Question::AnswerMethods
|
||||||
|
|
||||||
def ordered_answers(current_user: nil)
|
def ordered_answers(current_user: nil)
|
||||||
answers
|
answers
|
||||||
|
.includes([{ user: :profile }, :question])
|
||||||
.then do |query|
|
.then do |query|
|
||||||
next query unless current_user
|
next query unless current_user
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue