ActivityPub actions & side-effects in transaction
This commit is contained in:
parent
438394d404
commit
32d1e04817
8 changed files with 389 additions and 61 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue