PERF: Update TopicView#participant_count to use Topic#posts_count.

Use the counter cache instead of hitting the DB and plucking
every single id.
This commit is contained in:
Guo Xiang Tan 2018-06-27 17:18:47 +08:00
parent cfa7898c2d
commit eb427f7cf4

View File

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