Skip to content

A platform for community discussion. Free, open, simple.

PERF: Avoid running redundant bookmarks query for anon viewing topic (#19659)

Alan Guo Xiang Tanaf76f291e6a2
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index eeccb8bae89..63b6ec7580a 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -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
)