]> cat aescling's git repositories - mastodon.git/commitdiff
Fix follower and other counters being able to go negative (#18517)
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 26 May 2022 18:32:48 +0000 (20:32 +0200)
committersingle-right-quote <11325618-aescling@users.noreply.gitlab.com>
Fri, 27 May 2022 03:55:21 +0000 (23:55 -0400)
app/models/account_stat.rb
app/models/status_stat.rb

index b49827267af35255e991a29ed59a18394117c38b..a5d71a5b8cf03acb89b9075def8b34b54430b9c5 100644 (file)
@@ -20,4 +20,16 @@ class AccountStat < ApplicationRecord
   belongs_to :account, inverse_of: :account_stat
 
   update_index('accounts', :account)
+
+  def following_count
+    [attributes['following_count'], 0].max
+  end
+
+  def followers_count
+    [attributes['followers_count'], 0].max
+  end
+
+  def statuses_count
+    [attributes['statuses_count'], 0].max
+  end
 end
index 024c467e7150ffc055093fed9cb98612ffdb087f..437861d1c434cb5ce6e02caac37c4f07f28028b7 100644 (file)
@@ -17,6 +17,18 @@ class StatusStat < ApplicationRecord
 
   after_commit :reset_parent_cache
 
+  def replies_count
+    [attributes['replies_count'], 0].max
+  end
+
+  def reblogs_count
+    [attributes['reblogs_count'], 0].max
+  end
+
+  def favourites_count
+    [attributes['favourites_count'], 0].max
+  end
+
   private
 
   def reset_parent_cache