Various refactoring and typespec improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
21
lib/web/cache/activity_pub.ex
vendored
21
lib/web/cache/activity_pub.ex
vendored
@@ -23,15 +23,18 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
|
||||
@spec get_actor_by_name(String.t()) ::
|
||||
{:commit, ActorModel.t()} | {:ignore, nil}
|
||||
def get_actor_by_name(name) do
|
||||
Cachex.fetch(@cache, "actor_" <> name, fn "actor_" <> name ->
|
||||
case Actor.find_or_make_actor_from_nickname(name) do
|
||||
{:ok, %ActorModel{} = actor} ->
|
||||
{:commit, actor}
|
||||
Cachex.fetch(@cache, "actor_" <> name, &do_get_actor/1)
|
||||
end
|
||||
|
||||
nil ->
|
||||
{:ignore, nil}
|
||||
end
|
||||
end)
|
||||
@spec do_get_actor(String.t()) :: {:commit, Actor.t()} | {:ignore, nil}
|
||||
defp do_get_actor("actor_" <> name) do
|
||||
case Actor.find_or_make_actor_from_nickname(name) do
|
||||
{:ok, %ActorModel{} = actor} ->
|
||||
{:commit, actor}
|
||||
|
||||
{:error, _err} ->
|
||||
{:ignore, nil}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -179,7 +182,7 @@ defmodule Mobilizon.Web.Cache.ActivityPub do
|
||||
Gets a member by its UUID, with all associations loaded.
|
||||
"""
|
||||
@spec get_member_by_uuid_with_preload(String.t()) ::
|
||||
{:commit, Todo.t()} | {:ignore, nil}
|
||||
{:commit, Member.t()} | {:ignore, nil}
|
||||
def get_member_by_uuid_with_preload(uuid) do
|
||||
Cachex.fetch(@cache, "member_" <> uuid, fn "member_" <> uuid ->
|
||||
case Actors.get_member(uuid) do
|
||||
|
||||
18
lib/web/cache/cache.ex
vendored
18
lib/web/cache/cache.ex
vendored
@@ -3,7 +3,12 @@ defmodule Mobilizon.Web.Cache do
|
||||
Facade module which provides access to all cached data.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Actors.{Actor, Member}
|
||||
alias Mobilizon.Discussions.{Comment, Discussion}
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Posts.Post
|
||||
alias Mobilizon.Resources.Resource
|
||||
alias Mobilizon.Todos.{Todo, TodoList}
|
||||
alias Mobilizon.Web.Cache.ActivityPub
|
||||
import Mobilizon.Service.Guards, only: [is_valid_string: 1]
|
||||
|
||||
@@ -20,15 +25,26 @@ defmodule Mobilizon.Web.Cache do
|
||||
Enum.each(@caches, &Cachex.del(&1, "actor_" <> preferred_username))
|
||||
end
|
||||
|
||||
@spec get_actor_by_name(binary) :: {:commit, Actor.t()} | {:ignore, nil}
|
||||
defdelegate get_actor_by_name(name), to: ActivityPub
|
||||
@spec get_local_actor_by_name(binary) :: {:commit, Actor.t()} | {:ignore, nil}
|
||||
defdelegate get_local_actor_by_name(name), to: ActivityPub
|
||||
@spec get_public_event_by_uuid_with_preload(binary) :: {:commit, Event.t()} | {:ignore, nil}
|
||||
defdelegate get_public_event_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
@spec get_comment_by_uuid_with_preload(binary) :: {:commit, Comment.t()} | {:ignore, nil}
|
||||
defdelegate get_comment_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
@spec get_resource_by_uuid_with_preload(binary) :: {:commit, Resource.t()} | {:ignore, nil}
|
||||
defdelegate get_resource_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
@spec get_todo_list_by_uuid_with_preload(binary) :: {:commit, TodoList.t()} | {:ignore, nil}
|
||||
defdelegate get_todo_list_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
@spec get_todo_by_uuid_with_preload(binary) :: {:commit, Todo.t()} | {:ignore, nil}
|
||||
defdelegate get_todo_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
@spec get_member_by_uuid_with_preload(binary) :: {:commit, Member.t()} | {:ignore, nil}
|
||||
defdelegate get_member_by_uuid_with_preload(uuid), to: ActivityPub
|
||||
@spec get_post_by_slug_with_preload(binary) :: {:commit, Post.t()} | {:ignore, nil}
|
||||
defdelegate get_post_by_slug_with_preload(slug), to: ActivityPub
|
||||
@spec get_discussion_by_slug_with_preload(binary) :: {:commit, Discussion.t()} | {:ignore, nil}
|
||||
defdelegate get_discussion_by_slug_with_preload(slug), to: ActivityPub
|
||||
@spec get_relay :: {:commit, Actor.t()} | {:ignore, nil}
|
||||
defdelegate get_relay, to: ActivityPub
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user