Wrap context creation in transaction.
authorRoger Braun <roger@rogerbraun.net>
Sun, 30 Apr 2017 11:58:40 +0000 (13:58 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 30 Apr 2017 11:58:40 +0000 (13:58 +0200)
lib/pleroma/web/twitter_api/twitter_api.ex

index b2fb72a81597337508c16adb09761331d2ee5441..13dc3bd49172fb175a2bff00ebb0bef6f805325e 100644 (file)
@@ -319,13 +319,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
   end
 
   def context_to_conversation_id(context) do
-    with %Object{id: id} <- Object.get_by_ap_id(context) do
-      id
-    else _e ->
-      changeset = Object.context_mapping(context)
-      {:ok, %{id: id}} = Repo.insert(changeset)
-      id
-    end
+    {:ok, id} = Repo.transaction(fn ->
+      with %Object{id: id} <- Object.get_by_ap_id(context) do
+        id
+      else _e ->
+        changeset = Object.context_mapping(context)
+        {:ok, %{id: id}} = Repo.insert(changeset)
+        id
+      end
+    end)
+    id
   end
 
   def conversation_id_to_context(id) do