# 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