topic reply count resync for each new post
This commit is contained in:
parent
efa99eb242
commit
a7f92ec0c1
|
@ -487,6 +487,19 @@ class User < ActiveRecord::Base
|
|||
group('trust_level').count
|
||||
end
|
||||
|
||||
def update_topic_reply_count
|
||||
topic_reply_count =
|
||||
Topic
|
||||
.where(['id in (
|
||||
SELECT topic_id FROM posts p
|
||||
JOIN topics t2 ON t2.id = p.topic_id
|
||||
WHERE deleted_at IS NULL AND
|
||||
t2.user_id <> p.user_id AND
|
||||
p.user_id = ?
|
||||
)', self.id])
|
||||
.count
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def cook
|
||||
|
@ -567,4 +580,5 @@ class User < ActiveRecord::Base
|
|||
errors.add(:password, "must be 6 letters or longer")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -117,7 +117,7 @@ class PostCreator
|
|||
|
||||
|
||||
if @user.id != topic.user_id
|
||||
@user.topic_reply_count += 1
|
||||
@user.update_topic_reply_count
|
||||
end
|
||||
|
||||
@user.last_posted_at = post.created_at
|
||||
|
|
Loading…
Reference in New Issue