Browse Source

Shorten caching of quote posts pending approval (#37570)

pull/1371/head
Claire 2 months ago committed by Misty De Meo
parent
commit
c8177dc7e4
No known key found for this signature in database
GPG Key ID: 76CF846A2F674B2C
  1. 2
      app/controllers/statuses_controller.rb
  2. 11
      app/models/quote.rb

2
app/controllers/statuses_controller.rb

@ -29,7 +29,7 @@ class StatusesController < ApplicationController
end
format.json do
expires_in 3.minutes, public: true if @status.distributable? && public_fetch_mode?
expires_in @status.quote&.pending? ? 5.seconds : 3.minutes, public: true if @status.distributable? && public_fetch_mode?
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
end
end

11
app/models/quote.rb

@ -48,6 +48,8 @@ class Quote < ApplicationRecord
def accept!
update!(state: :accepted)
reset_parent_cache! if attribute_changed?(:state)
end
def reject!
@ -76,6 +78,15 @@ class Quote < ApplicationRecord
private
def reset_parent_cache!
return if status_id.nil?
Rails.cache.delete("v3:statuses/#{status_id}")
# This clears the web cache for the ActivityPub representation
Rails.cache.delete("statuses/show:v3:statuses/#{status_id}")
end
def set_accounts
self.account = status.account
self.quoted_account = quoted_status&.account

Loading…
Cancel
Save