forked from mirrors/catstodon
Fix follower and other counters being able to go negative (#18517)
This commit is contained in:
parent
702b709d9a
commit
3e0e7a1cfb
2 changed files with 24 additions and 0 deletions
|
@ -20,4 +20,16 @@ class AccountStat < ApplicationRecord
|
||||||
belongs_to :account, inverse_of: :account_stat
|
belongs_to :account, inverse_of: :account_stat
|
||||||
|
|
||||||
update_index('accounts', :account)
|
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
|
end
|
||||||
|
|
|
@ -17,6 +17,18 @@ class StatusStat < ApplicationRecord
|
||||||
|
|
||||||
after_commit :reset_parent_cache
|
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
|
private
|
||||||
|
|
||||||
def reset_parent_cache
|
def reset_parent_cache
|
||||||
|
|
Loading…
Reference in a new issue