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

@ -749,9 +749,18 @@ defmodule Pleroma.User do
Cachex.del(:user_cache, "nickname:#{user.nickname}")
end
@spec get_cached_by_ap_id(String.t()) :: User.t() | nil
def get_cached_by_ap_id(ap_id) do
key = "ap_id:#{ap_id}"
Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end)
with {:ok, nil} <- Cachex.get(:user_cache, key),
user when not is_nil(user) <- get_by_ap_id(ap_id),
{:ok, true} <- Cachex.put(:user_cache, key, user) do
user
else
{:ok, user} -> user
nil -> nil
end
end
def get_cached_by_id(id) do