about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-22 19:35:48 +0200
committerGitHub <noreply@github.com>2017-05-22 19:35:48 +0200
commit4a4733b397c9a5d3a69d7b2156f4f8aa62ff0c32 (patch)
treeb4df49db70e7dfaa9f7307f13cc79b4625c65d6b
parentbda739122110a36b620cb06cf850fa259aafa896 (diff)
Similarly to #2426, put creation of remote statuses in a transaction, (#3233)
so that public timeline/caching would not encounter incomplete data
-rw-r--r--app/services/process_feed_service.rb31
1 files changed, 18 insertions, 13 deletions
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index 28ace7ae9..10e947001 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -47,25 +47,30 @@ class ProcessFeedService < BaseService
         return
       end
 
+      status, just_created = nil
+
       Rails.logger.debug "Creating remote status #{id}"
-      status, just_created = status_from_xml(@xml)
 
-      return if status.nil?
-      return status unless just_created
+      ApplicationRecord.transaction do
+        status, just_created = status_from_xml(@xml)
+
+        return if status.nil?
+        return status unless just_created
 
-      if verb == :share
-        original_status = shared_status_from_xml(@xml.at_xpath('.//activity:object', activity: TagManager::AS_XMLNS))
-        status.reblog   = original_status
+        if verb == :share
+          original_status = shared_status_from_xml(@xml.at_xpath('.//activity:object', activity: TagManager::AS_XMLNS))
+          status.reblog   = original_status
 
-        if original_status.nil?
-          status.destroy
-          return nil
-        elsif original_status.reblog?
-          status.reblog = original_status.reblog
+          if original_status.nil?
+            status.destroy
+            return nil
+          elsif original_status.reblog?
+            status.reblog = original_status.reblog
+          end
         end
-      end
 
-      status.save!
+        status.save!
+      end
 
       notify_about_mentions!(status) unless status.reblog?
       notify_about_reblog!(status) if status.reblog? && status.reblog.account.local?