mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 20:03:15 +08:00
PERF: mega_topics get no post counts per user
This commit is contained in:
parent
f66efc601d
commit
2d59d06916
|
@ -278,21 +278,25 @@ class TopicView
|
|||
|
||||
def post_counts_by_user
|
||||
@post_counts_by_user ||= begin
|
||||
post_ids = unfiltered_post_ids
|
||||
if is_mega_topic?
|
||||
{}
|
||||
else
|
||||
post_ids = unfiltered_post_ids
|
||||
|
||||
return {} if post_ids.blank?
|
||||
return {} if post_ids.blank?
|
||||
|
||||
sql = <<~SQL
|
||||
SELECT user_id, count(*) AS count_all
|
||||
FROM posts
|
||||
WHERE id in (:post_ids)
|
||||
AND user_id IS NOT NULL
|
||||
GROUP BY user_id
|
||||
ORDER BY count_all DESC
|
||||
LIMIT #{MAX_PARTICIPANTS}
|
||||
SQL
|
||||
sql = <<~SQL
|
||||
SELECT user_id, count(*) AS count_all
|
||||
FROM posts
|
||||
WHERE id in (:post_ids)
|
||||
AND user_id IS NOT NULL
|
||||
GROUP BY user_id
|
||||
ORDER BY count_all DESC
|
||||
LIMIT #{MAX_PARTICIPANTS}
|
||||
SQL
|
||||
|
||||
Hash[*DB.query_single(sql, post_ids: post_ids)]
|
||||
Hash[*DB.query_single(sql, post_ids: post_ids)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user