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:<name>` or
`noteupdater:<name>` search. This is faster because it generates
better SQL.
This commit is contained in:
evazion
2022-04-05 01:04:02 -05:00
parent 71c8768fe2
commit 88be28ae36

View File

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