From 88be28ae36a36a1126ac933e13502c91b9247999 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 5 Apr 2022 01:04:02 -0500 Subject: [PATCH] users: optimize commented/noted post count on user profiles. Count the number of commented and noted posts directly, instead of indirectly by counting the number of posts in a `commenter:` or `noteupdater:` search. This is faster because it generates better SQL. --- app/presenters/user_presenter.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index 200a113ad..377b85d81 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -70,8 +70,7 @@ class UserPresenter end def commented_posts_count(template) - count = PostQuery.new("commenter:#{user.name}").fast_count - count = "?" if count.nil? + count = user.comments.distinct.count(:post_id) template.link_to(count, template.posts_path(tags: "commenter:#{user.name} order:comment_bumped"), rel: "nofollow") end @@ -84,8 +83,7 @@ class UserPresenter end def noted_posts_count(template) - count = PostQuery.new("noteupdater:#{user.name}").fast_count - count = "?" if count.nil? + count = user.note_versions.distinct.count(:post_id) template.link_to(count, template.posts_path(tags: "noteupdater:#{user.name} order:note"), rel: "nofollow") end