about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-03-08 01:47:36 +0100
committerGitHub <noreply@github.com>2019-03-08 01:47:36 +0100
commit29a09858f6700c0a6eb17797836589ed0839dec9 (patch)
tree96ac7fbac23d6ca32704c143342b5606523c8cab /app/services
parent38e9c66f34d7054357a3de63834f182734d43d75 (diff)
parentca45198ccbbdde88731f074fcab2b5c9310775c2 (diff)
Merge pull request #945 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/services')
-rw-r--r--app/services/activitypub/fetch_remote_poll_service.rb17
-rw-r--r--app/services/vote_service.rb2
2 files changed, 13 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
diff --git a/app/services/vote_service.rb b/app/services/vote_service.rb
index 8bab2810e..5b80da03a 100644
--- a/app/services/vote_service.rb
+++ b/app/services/vote_service.rb
@@ -11,6 +11,8 @@ class VoteService < BaseService
     @choices = choices
     @votes   = []
 
+    return if @poll.expired?
+
     ApplicationRecord.transaction do
       @choices.each do |choice|
         @votes << @poll.votes.create!(account: @account, choice: choice)