From: Roger Braun Date: Sun, 30 Apr 2017 11:58:40 +0000 (+0200) Subject: Wrap context creation in transaction. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=379caca01d818613ba7e013e8f0bebba160c6871;p=akkoma Wrap context creation in transaction. --- diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index b2fb72a81..13dc3bd49 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -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