From 9f079c2e8805ac223762ead0c6469e8ec2491c7a Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 7 Mar 2019 15:52:38 +0100 Subject: [PATCH] Handle StaleObjectError when retrieving polls (#10208) --- .../activitypub/fetch_remote_poll_service.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/services/activitypub/fetch_remote_poll_service.rb b/app/services/activitypub/fetch_remote_poll_service.rb index 1dd587d73a091d..4f9814fcd7e05f 100644 --- a/app/services/activitypub/fetch_remote_poll_service.rb +++ b/app/services/activitypub/fetch_remote_poll_service.rb @@ -32,12 +32,17 @@ def call(poll, on_behalf_of = nil) # votes, so we need to remove them poll.votes.delete_all if latest_options != poll.options - poll.update!( - last_fetched_at: Time.now.utc, - expires_at: expires_at, - options: latest_options, - cached_tallies: items.map { |item| item.dig('replies', 'totalItems') || 0 } - ) + begin + poll.update!( + last_fetched_at: Time.now.utc, + expires_at: expires_at, + options: latest_options, + cached_tallies: items.map { |item| item.dig('replies', 'totalItems') || 0 } + ) + rescue ActiveRecord::StaleObjectError + poll.reload + retry + end end private