2020-01-26 21:36:50 +01:00
|
|
|
defmodule Mobilizon.Web.Cache do
|
2019-09-17 23:39:26 +02:00
|
|
|
@moduledoc """
|
|
|
|
Facade module which provides access to all cached data.
|
|
|
|
"""
|
|
|
|
|
2021-09-24 16:46:42 +02:00
|
|
|
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}
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Cache.ActivityPub
|
2021-09-10 11:27:59 +02:00
|
|
|
import Mobilizon.Service.Guards, only: [is_valid_string: 1]
|
2019-09-17 23:39:26 +02:00
|
|
|
|
|
|
|
@caches [:activity_pub, :feed, :ics]
|
|
|
|
|
2021-09-10 11:27:59 +02:00
|
|
|
@type local_actor :: %Actor{domain: nil}
|
|
|
|
|
2019-09-17 23:39:26 +02:00
|
|
|
@doc """
|
2021-09-10 11:27:59 +02:00
|
|
|
Clears all caches for a local actor.
|
2019-09-17 23:39:26 +02:00
|
|
|
"""
|
2021-09-10 11:27:59 +02:00
|
|
|
@spec clear_cache(%Actor{domain: nil, preferred_username: String.t()}) :: :ok
|
|
|
|
def clear_cache(%Actor{preferred_username: preferred_username, domain: nil})
|
|
|
|
when is_valid_string(preferred_username) do
|
2019-09-17 23:39:26 +02:00
|
|
|
Enum.each(@caches, &Cachex.del(&1, "actor_" <> preferred_username))
|
|
|
|
end
|
|
|
|
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_actor_by_name(binary) :: {:commit, Actor.t()} | {:ignore, nil}
|
2020-08-14 11:32:23 +02:00
|
|
|
defdelegate get_actor_by_name(name), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_local_actor_by_name(binary) :: {:commit, Actor.t()} | {:ignore, nil}
|
2019-09-17 23:39:26 +02:00
|
|
|
defdelegate get_local_actor_by_name(name), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_public_event_by_uuid_with_preload(binary) :: {:commit, Event.t()} | {:ignore, nil}
|
2019-09-17 23:39:26 +02:00
|
|
|
defdelegate get_public_event_by_uuid_with_preload(uuid), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_comment_by_uuid_with_preload(binary) :: {:commit, Comment.t()} | {:ignore, nil}
|
2019-09-17 23:39:26 +02:00
|
|
|
defdelegate get_comment_by_uuid_with_preload(uuid), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_resource_by_uuid_with_preload(binary) :: {:commit, Resource.t()} | {:ignore, nil}
|
2020-02-18 08:57:00 +01:00
|
|
|
defdelegate get_resource_by_uuid_with_preload(uuid), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_todo_list_by_uuid_with_preload(binary) :: {:commit, TodoList.t()} | {:ignore, nil}
|
2020-02-18 08:57:00 +01:00
|
|
|
defdelegate get_todo_list_by_uuid_with_preload(uuid), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_todo_by_uuid_with_preload(binary) :: {:commit, Todo.t()} | {:ignore, nil}
|
2020-02-18 08:57:00 +01:00
|
|
|
defdelegate get_todo_by_uuid_with_preload(uuid), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_member_by_uuid_with_preload(binary) :: {:commit, Member.t()} | {:ignore, nil}
|
2020-08-19 11:28:23 +02:00
|
|
|
defdelegate get_member_by_uuid_with_preload(uuid), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_post_by_slug_with_preload(binary) :: {:commit, Post.t()} | {:ignore, nil}
|
2020-07-09 17:24:28 +02:00
|
|
|
defdelegate get_post_by_slug_with_preload(slug), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_discussion_by_slug_with_preload(binary) :: {:commit, Discussion.t()} | {:ignore, nil}
|
2020-07-09 17:24:28 +02:00
|
|
|
defdelegate get_discussion_by_slug_with_preload(slug), to: ActivityPub
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec get_relay :: {:commit, Actor.t()} | {:ignore, nil}
|
2019-09-17 23:39:26 +02:00
|
|
|
defdelegate get_relay, to: ActivityPub
|
|
|
|
end
|