Merge pull request #1013 from Retrospring/include-profile-in-paginators

Eager load profiles in paginators
This commit is contained in:
Karina Kwiatek 2023-01-28 22:53:34 +01:00 committed by GitHub
commit c6bda47657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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