Merge pull request #1013 from Retrospring/include-profile-in-paginators
Eager load profiles in paginators
This commit is contained in:
commit
c6bda47657
|
@ -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,6 +5,7 @@ module User::QuestionMethods
|
|||
|
||||
define_cursor_paginator :cursored_questions, :ordered_questions
|
||||
|
||||
# @return [ActiveRecord::Relation<Question>] List of questions sent by the user
|
||||
def ordered_questions(author_is_anonymous: nil, direct: nil)
|
||||
questions
|
||||
.where({ author_is_anonymous:, direct: }.compact)
|
||||
|
|
|
@ -6,10 +6,12 @@ module User::RelationshipMethods
|
|||
define_cursor_paginator :cursored_following_relationships, :ordered_following_relationships
|
||||
define_cursor_paginator :cursored_follower_relationships, :ordered_follower_relationships
|
||||
|
||||
# @return [ActiveRecord::Relation<Relationships::Follow>] List of the user's following relationships
|
||||
def ordered_following_relationships
|
||||
active_follow_relationships.reverse_order.includes(target: [:profile])
|
||||
end
|
||||
|
||||
# @return [ActiveRecord::Relation<Relationships::Follow>] List of the user's follower relationships
|
||||
def ordered_follower_relationships
|
||||
passive_follow_relationships.reverse_order.includes(source: [:profile])
|
||||
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 New Issue