don't count deleted comments towards user's comment count

This commit is contained in:
joshua stein 2016-07-31 12:33:17 -05:00
parent 5f04c3e52e
commit b5f6ab36a8
2 changed files with 8 additions and 0 deletions

View file

@ -22,6 +22,8 @@ class Comment < ActiveRecord::Base
:log_to_countinual
after_destroy :unassign_votes
scope :active, -> { where(:is_deleted => false, :is_moderated => false) }
DOWNVOTABLE_DAYS = 7
# after this many minutes old, a comment cannot be edited
@ -209,6 +211,7 @@ class Comment < ActiveRecord::Base
Comment.record_timestamps = true
self.story.update_comments_count!
self.user.update_comments_posted_count!
end
def deliver_mention_notifications
@ -456,5 +459,6 @@ class Comment < ActiveRecord::Base
Comment.record_timestamps = true
self.story.update_comments_count!
self.user.update_comments_posted_count!
end
end

View file

@ -219,6 +219,10 @@ class User < ActiveRecord::Base
Keystore.value_for("user:#{self.id}:comments_posted").to_i
end
def update_comments_posted_count!
Keystore.put("user:#{self.id}:comments_posted", self.comments.active.count)
end
def delete!
User.transaction do
self.comments.each{|c| c.delete_for_user(self) }