summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-05-26 20:32:48 +0200
committerGitHub <noreply@github.com>2022-05-26 20:32:48 +0200
commit3e0e7a1cfb617837ccada330afc13ed804c3c47b (patch)
treea12490cdfb5dd5f3815cc23ebef93da95cb55eba
parent702b709d9a8df2ed65c54d32d585a4cf5fe13de1 (diff)
Fix follower and other counters being able to go negative (#18517)
-rw-r--r--app/models/account_stat.rb12
-rw-r--r--app/models/status_stat.rb12
2 files changed, 24 insertions, 0 deletions
diff --git a/app/models/account_stat.rb b/app/models/account_stat.rb
index b49827267af..a5d71a5b8cf 100644
--- a/app/models/account_stat.rb
+++ b/app/models/account_stat.rb
@@ -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
diff --git a/app/models/status_stat.rb b/app/models/status_stat.rb
index 024c467e715..437861d1c43 100644
--- a/app/models/status_stat.rb
+++ b/app/models/status_stat.rb
@@ -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