Skip to content

Commit

Permalink
Handle StaleObjectError when retrieving polls (mastodon#10208)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Gargron committed Mar 7, 2019
1 parent 9a32458 commit 9f079c2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/services/activitypub/fetch_remote_poll_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f079c2

Please sign in to comment.