about summary refs log tree commit diff
path: root/app/services/activitypub
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-07 15:52:38 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-03-07 15:52:38 +0100
commit09c042aa10f2be4824fcb8e96c8a8ae6d324d12f (patch)
tree0ffb924083273bff7b1f6fd5fbf5648c8497a248 /app/services/activitypub
parent637c952ccbe5acae17bbf573f8cd24703379a615 (diff)
Handle StaleObjectError when retrieving polls (#10208)
Diffstat (limited to 'app/services/activitypub')
-rw-r--r--app/services/activitypub/fetch_remote_poll_service.rb17
1 files 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 1dd587d73..4f9814fcd 100644
--- a/app/services/activitypub/fetch_remote_poll_service.rb
+++ b/app/services/activitypub/fetch_remote_poll_service.rb
@@ -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