Handle StaleObjectError when retrieving polls (#10208)

pull/945/head
ThibG 2019-03-07 15:52:38 +01:00 committed by Eugen Rochko
parent 637c952ccb
commit 09c042aa10
1 changed files with 11 additions and 6 deletions

View File

@ -32,12 +32,17 @@ class ActivityPub::FetchRemotePollService < BaseService
# votes, so we need to remove them # votes, so we need to remove them
poll.votes.delete_all if latest_options != poll.options poll.votes.delete_all if latest_options != poll.options
poll.update!( begin
last_fetched_at: Time.now.utc, poll.update!(
expires_at: expires_at, last_fetched_at: Time.now.utc,
options: latest_options, expires_at: expires_at,
cached_tallies: items.map { |item| item.dig('replies', 'totalItems') || 0 } options: latest_options,
) cached_tallies: items.map { |item| item.dig('replies', 'totalItems') || 0 }
)
rescue ActiveRecord::StaleObjectError
poll.reload
retry
end
end end
private private