about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorKeiji, Yoshimi <walf443@gmail.com>2017-04-26 10:47:44 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-04-26 03:47:44 +0200
commit8fe36654efff73cb9b6800f7d1a57e6466f2ded3 (patch)
tree0f853995e151fd6b723d26dd6a32606266b6425a /app/services
parent8ee1af95306e4016644ddfd257929eb61851d8fa (diff)
attach_media should be in transaction of creation status (#2426)
Diffstat (limited to 'app/services')
-rw-r--r--app/services/post_status_service.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 958cc2890..30b8032ed 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -20,15 +20,17 @@ class PostStatusService < BaseService
     end
 
     media  = validate_media!(options[:media_ids])
-    status = account.statuses.create!(text: text,
-                                      thread: in_reply_to,
-                                      sensitive: options[:sensitive],
-                                      spoiler_text: options[:spoiler_text] || '',
-                                      visibility: options[:visibility],
-                                      language: detect_language_for(text, account),
-                                      application: options[:application])
-
-    attach_media(status, media)
+    status = nil
+    ApplicationRecord.transaction do
+      status = account.statuses.create!(text: text,
+                                        thread: in_reply_to,
+                                        sensitive: options[:sensitive],
+                                        spoiler_text: options[:spoiler_text] || '',
+                                        visibility: options[:visibility],
+                                        language: detect_language_for(text, account),
+                                        application: options[:application])
+      attach_media(status, media)
+    end
     process_mentions_service.call(status)
     process_hashtags_service.call(status)