Avoid nested transactions when fetching quote posts (#35657)

This commit is contained in:
Claire 2025-08-04 16:34:05 +02:00 committed by GitHub
parent 49dcbd22d6
commit 0153a239db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -66,6 +66,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
resolve_thread(@status) resolve_thread(@status)
resolve_unresolved_mentions(@status) resolve_unresolved_mentions(@status)
fetch_replies(@status) fetch_replies(@status)
fetch_and_verify_quote
distribute distribute
forward_for_reply forward_for_reply
end end
@ -206,11 +207,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
@quote.status = status @quote.status = status
@quote.save @quote.save
embedded_quote = safe_prefetched_embed(@account, @status_parser.quoted_object, @json['context'])
ActivityPub::VerifyQuoteService.new.call(@quote, fetchable_quoted_uri: @quote_uri, prefetched_quoted_object: embedded_quote, request_id: @options[:request_id], depth: @options[:depth])
rescue Mastodon::RecursionLimitExceededError, Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
ActivityPub::RefetchAndVerifyQuoteWorker.perform_in(rand(30..600).seconds, @quote.id, @quote_uri, { 'request_id' => @options[:request_id] })
end end
def process_tags def process_tags
@ -380,6 +376,15 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
Rails.logger.warn "Error fetching replies: #{e}" Rails.logger.warn "Error fetching replies: #{e}"
end end
def fetch_and_verify_quote
return if @quote.nil?
embedded_quote = safe_prefetched_embed(@account, @status_parser.quoted_object, @json['context'])
ActivityPub::VerifyQuoteService.new.call(@quote, fetchable_quoted_uri: @quote_uri, prefetched_quoted_object: embedded_quote, request_id: @options[:request_id], depth: @options[:depth])
rescue Mastodon::RecursionLimitExceededError, Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
ActivityPub::RefetchAndVerifyQuoteWorker.perform_in(rand(30..600).seconds, @quote.id, @quote_uri, { 'request_id' => @options[:request_id] })
end
def conversation_from_uri(uri) def conversation_from_uri(uri)
return nil if uri.nil? return nil if uri.nil?
return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri) return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)

View File

@ -18,6 +18,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
@poll_changed = false @poll_changed = false
@quote_changed = false @quote_changed = false
@request_id = request_id @request_id = request_id
@quote = nil
# Only native types can be updated at the moment # Only native types can be updated at the moment
return @status if !expected_type? || already_updated_more_recently? return @status if !expected_type? || already_updated_more_recently?
@ -49,6 +50,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
create_edits! create_edits!
end end
fetch_and_verify_quote!(@quote, @status_parser.quote_uri) if @quote.present?
download_media_files! download_media_files!
queue_poll_notifications! queue_poll_notifications!
@ -312,10 +314,10 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
@quote_changed = true @quote_changed = true
end end
@quote = quote
quote.save quote.save
fetch_and_verify_quote!(quote, quote_uri)
elsif @status.quote.present? elsif @status.quote.present?
@quote = nil
@status.quote.destroy! @status.quote.destroy!
@quote_changed = true @quote_changed = true
end end