mirror of
https://github.com/discourse/discourse.git
synced 2025-03-28 12:25:39 +08:00
PERF: Simplify query of UserStat#update_topic_reply_count
.
For a user with alot of posts, we get a 25% speed up.
This commit is contained in:
parent
f524f8f811
commit
f0f3deb32b
@ -129,15 +129,11 @@ class UserStat < ActiveRecord::Base
|
||||
# topic_reply_count is a count of posts in other users' topics
|
||||
def update_topic_reply_count
|
||||
self.topic_reply_count =
|
||||
Topic
|
||||
.where(['id in (
|
||||
SELECT topic_id FROM posts p
|
||||
JOIN topics t2 ON t2.id = p.topic_id
|
||||
WHERE p.deleted_at IS NULL AND
|
||||
t2.user_id <> p.user_id AND
|
||||
p.user_id = ?
|
||||
)', self.user_id])
|
||||
.count
|
||||
Topic
|
||||
.joins("INNER JOIN posts ON topics.id = posts.topic_id AND topics.user_id <> posts.user_id")
|
||||
.where("posts.deleted_at IS NULL AND posts.user_id = ?", self.user_id)
|
||||
.distinct
|
||||
.count
|
||||
end
|
||||
|
||||
MAX_TIME_READ_DIFF = 100
|
||||
|
Loading…
x
Reference in New Issue
Block a user