Move caching to MobilizonWeb
This commit is contained in:
@@ -11,6 +11,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
alias Mobilizon.Service.Federator
|
||||
|
||||
alias MobilizonWeb.ActivityPub.ActorView
|
||||
alias MobilizonWeb.Cache
|
||||
|
||||
require Logger
|
||||
|
||||
@@ -113,13 +114,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
end
|
||||
|
||||
def relay(conn, _params) do
|
||||
with {status, actor} <-
|
||||
Cachex.fetch(
|
||||
:activity_pub,
|
||||
"relay_actor",
|
||||
&Mobilizon.Service.ActivityPub.Relay.get_actor/0
|
||||
),
|
||||
true <- status in [:ok, :commit] do
|
||||
with {:commit, %Actor{} = actor} <- Cache.get_relay() do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|> json(ActorView.render("actor.json", %{actor: actor}))
|
||||
|
||||
@@ -8,60 +8,60 @@ defmodule MobilizonWeb.FeedController do
|
||||
|
||||
def actor(conn, %{"name" => name, "format" => "atom"}) do
|
||||
case Cachex.fetch(:feed, "actor_" <> name) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
{:commit, data} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
_ ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def actor(conn, %{"name" => name, "format" => "ics"}) do
|
||||
case Cachex.fetch(:ics, "actor_" <> name) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
{:commit, data} ->
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
_ ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def event(conn, %{"uuid" => uuid, "format" => "ics"}) do
|
||||
case Cachex.fetch(:ics, "event_" <> uuid) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
{:commit, data} ->
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
_ ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def going(conn, %{"token" => token, "format" => "ics"}) do
|
||||
case Cachex.fetch(:ics, "token_" <> token) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
{:commit, data} ->
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
_ ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def going(conn, %{"token" => token, "format" => "atom"}) do
|
||||
case Cachex.fetch(:feed, "token_" <> token) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
{:commit, data} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
{:ignore, _} ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@ defmodule MobilizonWeb.PageController do
|
||||
Controller to load our webapp
|
||||
"""
|
||||
use MobilizonWeb, :controller
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Events
|
||||
|
||||
alias MobilizonWeb.Cache
|
||||
|
||||
plug(:put_layout, false)
|
||||
action_fallback(MobilizonWeb.FallbackController)
|
||||
@@ -12,17 +12,17 @@ defmodule MobilizonWeb.PageController do
|
||||
def index(conn, _params), do: render(conn, :index)
|
||||
|
||||
def actor(conn, %{"name" => name}) do
|
||||
{status, actor} = Actors.get_cached_local_actor_by_name(name)
|
||||
{status, actor} = Cache.get_local_actor_by_name(name)
|
||||
render_or_error(conn, &ok_status?/2, status, :actor, actor)
|
||||
end
|
||||
|
||||
def event(conn, %{"uuid" => uuid}) do
|
||||
{status, event} = Events.get_cached_public_event_by_uuid_with_preload(uuid)
|
||||
{status, event} = Cache.get_public_event_by_uuid_with_preload(uuid)
|
||||
render_or_error(conn, &ok_status_and_is_visible?/2, status, :event, event)
|
||||
end
|
||||
|
||||
def comment(conn, %{"uuid" => uuid}) do
|
||||
{status, comment} = Events.get_cached_comment_by_uuid_with_preload(uuid)
|
||||
{status, comment} = Cache.get_comment_by_uuid_with_preload(uuid)
|
||||
render_or_error(conn, &ok_status_and_is_visible?/2, status, :comment, comment)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user