mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:29:53 +01:00
Eager load profiles in paginators
This commit is contained in:
parent
4dcc5dea55
commit
32ba17ac72
3 changed files with 10 additions and 4 deletions
|
@ -5,10 +5,11 @@ module User::AnswerMethods
|
|||
|
||||
define_cursor_paginator :cursored_answers, :ordered_answers
|
||||
|
||||
# @return [ActiveRecord::Relation<Answer>] List of a user's answers
|
||||
def ordered_answers
|
||||
answers
|
||||
.order(:created_at)
|
||||
.reverse_order
|
||||
.includes(comments: [:user, :smiles], question: [:user], smiles: [:user])
|
||||
.includes(comments: %i[user smiles], question: { user: :profile }, smiles: [:user])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,9 +5,10 @@ module User::InboxMethods
|
|||
|
||||
define_cursor_paginator :cursored_inbox, :ordered_inbox
|
||||
|
||||
# @return [ActiveRecord::Relation<Inbox>] the user's inbox entries
|
||||
def ordered_inbox
|
||||
inboxes
|
||||
.includes(:question, :user)
|
||||
.includes(:question, user: :profile)
|
||||
.order(:created_at)
|
||||
.reverse_order
|
||||
end
|
||||
|
|
|
@ -5,8 +5,12 @@ module User::TimelineMethods
|
|||
|
||||
define_cursor_paginator :cursored_timeline, :timeline
|
||||
|
||||
# @return [Array] the users' timeline
|
||||
# @return [ActiveRecord::Relation<Answer>] the user's timeline
|
||||
def timeline
|
||||
Answer.where("user_id in (?) OR user_id = ?", following_ids, id).order(:created_at).reverse_order.includes(comments: %i[user smiles], question: [:user], user: [:profile], smiles: [:user])
|
||||
Answer
|
||||
.where("user_id in (?) OR user_id = ?", following_ids, id)
|
||||
.order(:created_at)
|
||||
.reverse_order
|
||||
.includes(comments: %i[user smiles], question: { user: :profile }, user: [:profile], smiles: [:user])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue