From eb427f7cf4bffaa08f2cbeb7eadb10a3da030124 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 27 Jun 2018 17:18:47 +0800 Subject: [PATCH] PERF: Update `TopicView#participant_count` to use `Topic#posts_count`. Use the counter cache instead of hitting the DB and plucking every single id. --- lib/topic_view.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index be2819d8e1e..09c9b2620ec 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -310,7 +310,7 @@ class TopicView @participant_count ||= begin if participants.size == MAX_PARTICIPANTS - if unfiltered_post_ids.length > MAX_POSTS_COUNT_PARTICIPANTS + if @topic.posts_count > MAX_POSTS_COUNT_PARTICIPANTS @topic.participant_count else sql = <<~SQL