Handle actor refreshment being impossible

If we can't refresh the actor, just return the stale actor

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-12-28 11:08:39 +01:00
parent 722bb67fb9
commit 7f665daaf3
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -33,7 +33,10 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
case Actors.get_actor_by_url(url, preload) do case Actors.get_actor_by_url(url, preload) do
{:ok, %Actor{} = cached_actor} -> {:ok, %Actor{} = cached_actor} ->
if Actors.needs_update?(cached_actor) do if Actors.needs_update?(cached_actor) do
__MODULE__.make_actor_from_url(url, options) case __MODULE__.make_actor_from_url(url, options) do
{:ok, %Actor{} = actor} -> {:ok, actor}
{:error, _} -> {:ok, cached_actor}
end
else else
{:ok, cached_actor} {:ok, cached_actor}
end end
@ -83,11 +86,14 @@ defmodule Mobilizon.Federation.ActivityPub.Actor do
Logger.debug("Finding or making actor from nickname #{nickname}") Logger.debug("Finding or making actor from nickname #{nickname}")
case Actors.get_actor_by_name_with_preload(nickname, type) do case Actors.get_actor_by_name_with_preload(nickname, type) do
%Actor{url: actor_url} = actor -> %Actor{url: actor_url} = cached_actor ->
if Actors.needs_update?(actor) do if Actors.needs_update?(cached_actor) do
make_actor_from_url(actor_url, preload: true) case __MODULE__.make_actor_from_url(actor_url, preload: true) do
{:ok, %Actor{} = actor} -> {:ok, actor}
{:error, _} -> {:ok, cached_actor}
end
else else
{:ok, actor} {:ok, cached_actor}
end end
nil -> nil ->