Stale user refreshing should be done async to prevent blocking of rendering activities
This commit is contained in:
parent
38e6166d93
commit
e37845cd35
1
changelog.d/user-refresh.change
Normal file
1
changelog.d/user-refresh.change
Normal file
@ -0,0 +1 @@
|
|||||||
|
User profile refreshes are now asynchronous
|
@ -183,6 +183,8 @@ config :pleroma, Pleroma.Emoji.Loader, test_emoji: true
|
|||||||
|
|
||||||
config :pleroma, Pleroma.Web.RichMedia.Backfill, provider: Pleroma.Web.RichMedia.Backfill
|
config :pleroma, Pleroma.Web.RichMedia.Backfill, provider: Pleroma.Web.RichMedia.Backfill
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.User, sync_refreshing: true
|
||||||
|
|
||||||
if File.exists?("./config/test.secret.exs") do
|
if File.exists?("./config/test.secret.exs") do
|
||||||
import_config "test.secret.exs"
|
import_config "test.secret.exs"
|
||||||
else
|
else
|
||||||
|
@ -2154,20 +2154,23 @@ defmodule Pleroma.User do
|
|||||||
|
|
||||||
def fetch_by_ap_id(ap_id), do: ActivityPub.make_user_from_ap_id(ap_id)
|
def fetch_by_ap_id(ap_id), do: ActivityPub.make_user_from_ap_id(ap_id)
|
||||||
|
|
||||||
|
@spec get_or_fetch_by_ap_id(String.t()) :: {:ok, User.t()} | {:error, any()}
|
||||||
def get_or_fetch_by_ap_id(ap_id) do
|
def get_or_fetch_by_ap_id(ap_id) do
|
||||||
cached_user = get_cached_by_ap_id(ap_id)
|
with cached_user = %User{} <- get_cached_by_ap_id(ap_id),
|
||||||
|
_ <- maybe_refresh(cached_user) do
|
||||||
|
{:ok, cached_user}
|
||||||
|
else
|
||||||
|
_ -> fetch_by_ap_id(ap_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
maybe_fetched_user = needs_update?(cached_user) && fetch_by_ap_id(ap_id)
|
defp maybe_refresh(user) do
|
||||||
|
fun = fn -> needs_update?(user) && fetch_by_ap_id(user.ap_id) end
|
||||||
|
|
||||||
case {cached_user, maybe_fetched_user} do
|
if Config.get([__MODULE__, :sync_refreshing], false) do
|
||||||
{_, {:ok, %User{} = user}} ->
|
fun.()
|
||||||
{:ok, user}
|
else
|
||||||
|
Task.start(fun)
|
||||||
{%User{} = user, _} ->
|
|
||||||
{:ok, user}
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
{:error, :not_found}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -953,9 +953,12 @@ defmodule Pleroma.UserTest do
|
|||||||
|
|
||||||
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||||
|
|
||||||
assert user.inbox
|
# User was updated async, fetch from cache now
|
||||||
|
updated_user = User.get_cached_by_ap_id(user.ap_id)
|
||||||
|
|
||||||
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
assert updated_user.inbox
|
||||||
|
|
||||||
|
refute updated_user.last_refreshed_at == orig_user.last_refreshed_at
|
||||||
end
|
end
|
||||||
|
|
||||||
test "if nicknames clash, the old user gets a prefix with the old id to the nickname" do
|
test "if nicknames clash, the old user gets a prefix with the old id to the nickname" do
|
||||||
|
Loading…
Reference in New Issue
Block a user