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:
@@ -70,8 +70,7 @@ class UserPresenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def commented_posts_count(template)
|
def commented_posts_count(template)
|
||||||
count = PostQuery.new("commenter:#{user.name}").fast_count
|
count = user.comments.distinct.count(:post_id)
|
||||||
count = "?" if count.nil?
|
|
||||||
template.link_to(count, template.posts_path(tags: "commenter:#{user.name} order:comment_bumped"), rel: "nofollow")
|
template.link_to(count, template.posts_path(tags: "commenter:#{user.name} order:comment_bumped"), rel: "nofollow")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -84,8 +83,7 @@ class UserPresenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def noted_posts_count(template)
|
def noted_posts_count(template)
|
||||||
count = PostQuery.new("noteupdater:#{user.name}").fast_count
|
count = user.note_versions.distinct.count(:post_id)
|
||||||
count = "?" if count.nil?
|
|
||||||
template.link_to(count, template.posts_path(tags: "noteupdater:#{user.name} order:note"), rel: "nofollow")
|
template.link_to(count, template.posts_path(tags: "noteupdater:#{user.name} order:note"), rel: "nofollow")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user