mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-04 03:25:14 +00:00
Add quotes_count to statuses stats (#35832)
This commit is contained in:
parent
94ad088482
commit
2560242972
13 changed files with 94 additions and 9 deletions
|
|
@ -40,6 +40,10 @@ class Quote < ApplicationRecord
|
|||
validates :approval_uri, absence: true, if: -> { quoted_account&.local? }
|
||||
validate :validate_visibility
|
||||
|
||||
after_create_commit :increment_counter_caches!
|
||||
after_destroy_commit :decrement_counter_caches!
|
||||
after_update_commit :update_counter_caches!
|
||||
|
||||
def accept!
|
||||
update!(state: :accepted)
|
||||
end
|
||||
|
|
@ -84,4 +88,27 @@ class Quote < ApplicationRecord
|
|||
def set_activity_uri
|
||||
self.activity_uri = [ActivityPub::TagManager.instance.uri_for(account), '/quote_requests/', SecureRandom.uuid].join
|
||||
end
|
||||
|
||||
def increment_counter_caches!
|
||||
return unless acceptable?
|
||||
|
||||
quoted_status&.increment_count!(:quotes_count)
|
||||
end
|
||||
|
||||
def decrement_counter_caches!
|
||||
return unless acceptable?
|
||||
|
||||
quoted_status&.decrement_count!(:quotes_count)
|
||||
end
|
||||
|
||||
def update_counter_caches!
|
||||
return if legacy? || !state_previously_changed?
|
||||
|
||||
if acceptable?
|
||||
quoted_status&.increment_count!(:quotes_count)
|
||||
else
|
||||
# TODO: are there cases where this would not be correct?
|
||||
quoted_status&.decrement_count!(:quotes_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue