topic reply count resync for each new post

This commit is contained in:
Sam 2013-04-05 16:48:38 +11:00
parent efa99eb242
commit a7f92ec0c1
2 changed files with 15 additions and 1 deletions

View File

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

View File

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