Move caching to MobilizonWeb

This commit is contained in:
miffigriffi
2019-09-17 23:39:26 +02:00
parent 8f580ce10c
commit 48dbec51f5
9 changed files with 112 additions and 81 deletions

View File

@@ -351,17 +351,6 @@ defmodule Mobilizon.Actors.Actor do
|> URI.decode()
end
@doc """
Clear multiple caches for an actor
"""
# TODO: move to MobilizonWeb
@spec clear_cache(t) :: {:ok, true}
def clear_cache(%__MODULE__{preferred_username: preferred_username, domain: nil}) do
Cachex.del(:activity_pub, "actor_" <> preferred_username)
Cachex.del(:feed, "actor_" <> preferred_username)
Cachex.del(:ics, "actor_" <> preferred_username)
end
@spec build_relay_creation_attrs(map) :: map
defp build_relay_creation_attrs(%{url: url, preferred_username: preferred_username}) do
%{

View File

@@ -160,24 +160,6 @@ defmodule Mobilizon.Actors do
|> Repo.preload(:organized_events)
end
@doc """
Gets a cached local actor by username.
#TODO: move to MobilizonWeb layer
"""
@spec get_cached_local_actor_by_name(String.t()) ::
{:commit, Actor.t()} | {:ignore, any()}
def get_cached_local_actor_by_name(name) do
Cachex.fetch(:activity_pub, "actor_" <> name, fn "actor_" <> name ->
case get_local_actor_by_name(name) do
nil ->
{:ignore, nil}
%Actor{} = actor ->
{:commit, actor}
end
end)
end
@doc """
Creates an actor.
"""

View File

@@ -225,21 +225,6 @@ defmodule Mobilizon.Events do
|> Repo.one()
end
# TODO: move to MobilizonWeb
@spec get_cached_public_event_by_uuid_with_preload(String.t()) ::
{:commit, Event.t()} | {:ignore, nil}
def get_cached_public_event_by_uuid_with_preload(uuid) do
Cachex.fetch(:activity_pub, "event_" <> uuid, fn "event_" <> uuid ->
case get_public_event_by_uuid_with_preload(uuid) do
%Event{} = event ->
{:commit, event}
nil ->
{:ignore, nil}
end
end)
end
@doc """
Creates an event.
"""
@@ -837,21 +822,6 @@ defmodule Mobilizon.Events do
|> Repo.preload(@comment_preloads)
end
# TODO: move to MobilizonWeb
@spec get_cached_comment_by_uuid_with_preload(String.t()) ::
{:commit, Comment.t()} | {:ignore, nil}
def get_cached_comment_by_uuid_with_preload(uuid) do
Cachex.fetch(:activity_pub, "comment_" <> uuid, fn "comment_" <> uuid ->
case get_comment_from_uuid_with_preload(uuid) do
%Comment{} = comment ->
{:commit, comment}
nil ->
{:ignore, nil}
end
end)
end
@doc """
Creates a comment.
"""