From a18c4daf4c7a7acad485ccd92e954d32311bac1c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 3 May 2022 11:40:16 +0200 Subject: [PATCH] Avoid using actor id from config cache Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/event/utils.ex | 8 ++++---- lib/mobilizon/config.ex | 12 ------------ lib/mobilizon/events/events.ex | 3 ++- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/graphql/resolvers/event/utils.ex b/lib/graphql/resolvers/event/utils.ex index a120f8e7..c4d014ae 100644 --- a/lib/graphql/resolvers/event/utils.ex +++ b/lib/graphql/resolvers/event/utils.ex @@ -4,9 +4,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Event.Utils do """ alias Mobilizon.Actors.Actor - alias Mobilizon.{Config, Events} + alias Mobilizon.Events alias Mobilizon.Events.Event - alias Mobilizon.Federation.ActivityPub.Permission + alias Mobilizon.Federation.ActivityPub.{Permission, Relay} import Mobilizon.Service.Guards, only: [is_valid_string: 1] @spec can_event_be_updated_by?(Event.t(), Actor.t()) :: @@ -43,7 +43,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event.Utils do def check_event_access?(%Event{local: true}), do: true def check_event_access?(%Event{url: url}) do - relay_actor_id = Config.relay_actor_id() - Events.check_if_event_has_instance_follow(url, relay_actor_id) + relay_actor = Relay.get_actor() + Events.check_if_event_has_instance_follow(url, relay_actor.id) end end diff --git a/lib/mobilizon/config.ex b/lib/mobilizon/config.ex index cf07051b..abafe9ec 100644 --- a/lib/mobilizon/config.ex +++ b/lib/mobilizon/config.ex @@ -322,8 +322,6 @@ defmodule Mobilizon.Config do @spec anonymous_actor_id :: integer def anonymous_actor_id, do: get_cached_value(:anonymous_actor_id) - @spec relay_actor_id :: integer - def relay_actor_id, do: get_cached_value(:relay_actor_id) @spec admin_settings :: map def admin_settings, do: get_cached_value(:admin_config) @@ -401,16 +399,6 @@ defmodule Mobilizon.Config do end end - defp create_cache(:relay_actor_id) do - case Actors.get_or_create_internal_actor("relay") do - {:ok, %{id: actor_id}} -> - {:ok, actor_id} - - {:error, err} -> - {:error, err} - end - end - defp create_cache(:admin_config) do data = %{ instance_description: instance_description(), diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index c894d028..8287b4e9 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -28,6 +28,7 @@ defmodule Mobilizon.Events do Track } + alias Mobilizon.Federation.ActivityPub.Relay alias Mobilizon.Service.Export.Cachable alias Mobilizon.Service.Workers.BuildSearch alias Mobilizon.Service.Workers.EventDelayedNotificationWorker @@ -1676,7 +1677,7 @@ defmodule Mobilizon.Events do @spec filter_local_or_from_followed_instances_events(Ecto.Queryable.t()) :: Ecto.Query.t() defp filter_local_or_from_followed_instances_events(query) do - follower_actor_id = Mobilizon.Config.relay_actor_id() + %Actor{id: follower_actor_id} = Relay.get_actor() query |> join(:left, [q], s in Share, on: s.uri == q.url)