ActivityPub actions & side-effects in transaction

This commit is contained in:
Alexander Strizhakov 2019-12-30 11:30:20 +03:00
commit 32d1e04817
No known key found for this signature in database
GPG key ID: 022896A53AEF1381
8 changed files with 389 additions and 61 deletions

View file

@ -145,18 +145,18 @@ defmodule Pleroma.Object do
# Legacy objects can be mutated by anybody
def authorize_mutation(%Object{}, %User{}), do: true
@spec get_cached_by_ap_id(String.t()) :: Object.t() | nil
def get_cached_by_ap_id(ap_id) do
key = "object:#{ap_id}"
Cachex.fetch!(:object_cache, key, fn _ ->
object = get_by_ap_id(ap_id)
if object do
{:commit, object}
else
{:ignore, object}
end
end)
with {:ok, nil} <- Cachex.get(:object_cache, key),
object when not is_nil(object) <- get_by_ap_id(ap_id),
{:ok, true} <- Cachex.put(:object_cache, key, object) do
object
else
{:ok, object} -> object
nil -> nil
end
end
def context_mapping(context) do