Browse Source

Handle StaleObjectError when retrieving polls (#10208)

pull/4/head
ThibG 5 years ago
committed by Eugen Rochko
parent
commit
09c042aa10
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      app/services/activitypub/fetch_remote_poll_service.rb

+ 11
- 6
app/services/activitypub/fetch_remote_poll_service.rb View File

@ -32,12 +32,17 @@ class ActivityPub::FetchRemotePollService < BaseService
# 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

Loading…
Cancel
Save