]> cat aescling's git repositories - mastodon.git/commitdiff
Handle StaleObjectError when retrieving polls (#10208)
authorThibG <thib@sitedethib.com>
Thu, 7 Mar 2019 14:52:38 +0000 (15:52 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 7 Mar 2019 14:52:38 +0000 (15:52 +0100)
app/services/activitypub/fetch_remote_poll_service.rb

index 1dd587d73a091d85155690a5959a671a4bf80a54..4f9814fcd7e05fb1cc7e1e6549ad09e2845b749a 100644 (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