PERF: Avoid running redundant bookmarks query for anon viewing topic (#19659)
The `TopicView#bookmarks` method is called by `TopicViewSerializer` and `PostSerializer` so we want to avoid running a meaningless query when user is not present.
This commit is contained in:
parent
24db6fbb73
commit
af76f291e6
|
@ -412,12 +412,13 @@ class TopicView
|
|||
end
|
||||
|
||||
def has_bookmarks?
|
||||
return false if @user.blank?
|
||||
return false if @topic.trashed?
|
||||
bookmarks.any?
|
||||
end
|
||||
|
||||
def bookmarks
|
||||
return [] if @user.blank?
|
||||
return [] if @topic.trashed?
|
||||
|
||||
@bookmarks ||= Bookmark.for_user_in_topic(@user, @topic.id).select(
|
||||
:id, :bookmarkable_id, :bookmarkable_type, :reminder_at, :name, :auto_delete_preference
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue