mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: Only load the current user's topic_user for bookmarks list (#17873)
Previously, for every bookmarked topic, all topic_user records were being preloaded. Only the current user's record is actually required. This commit introduces a new `perform_custom_preload!` API which bookmarkables can use to add custom preloading logic. We use this in topic_bookmarkable to load just the topic_user data we need (in the same way as `topic_list.rb`). Co-authored-by: Blake Erickson <o.blakeerickson@gmail.com>
This commit is contained in:
@@ -15,7 +15,6 @@ class UserPostTopicBookmarkBaseSerializer < UserBookmarkBaseSerializer
|
||||
:archived,
|
||||
:archetype,
|
||||
:highest_post_number,
|
||||
:last_read_post_number,
|
||||
:bumped_at,
|
||||
:slug
|
||||
|
||||
@@ -51,10 +50,6 @@ class UserPostTopicBookmarkBaseSerializer < UserBookmarkBaseSerializer
|
||||
scope.is_whisperer? ? topic.highest_staff_post_number : topic.highest_post_number
|
||||
end
|
||||
|
||||
def last_read_post_number
|
||||
topic_user&.last_read_post_number
|
||||
end
|
||||
|
||||
def bumped_at
|
||||
topic.bumped_at
|
||||
end
|
||||
@@ -62,10 +57,4 @@ class UserPostTopicBookmarkBaseSerializer < UserBookmarkBaseSerializer
|
||||
def slug
|
||||
topic.slug
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic_user
|
||||
@topic_user ||= topic.topic_users.find { |tu| tu.user_id == scope.user.id }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,9 @@ class UserTopicBookmarkSerializer < UserPostTopicBookmarkBaseSerializer
|
||||
# it does not matter what the linked post number is for topic bookmarks,
|
||||
# on the client we always take the user to the last unread post in the
|
||||
# topic when the bookmark URL is clicked
|
||||
|
||||
attributes :last_read_post_number
|
||||
|
||||
def linked_post_number
|
||||
1
|
||||
end
|
||||
@@ -63,9 +66,17 @@ class UserTopicBookmarkSerializer < UserPostTopicBookmarkBaseSerializer
|
||||
end
|
||||
end
|
||||
|
||||
def last_read_post_number
|
||||
topic_user&.last_read_post_number
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic
|
||||
object.bookmarkable
|
||||
end
|
||||
|
||||
def topic_user
|
||||
topic.user_data
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user