From b5f6ab36a8ee3a0d163e2f05f0b1c191abd7adc0 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Sun, 31 Jul 2016 12:33:17 -0500 Subject: [PATCH] don't count deleted comments towards user's comment count --- app/models/comment.rb | 4 ++++ app/models/user.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index 776368b..6844118 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 60878b3..366db85 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) }