Add logging for when cached iCalendar feed data can't be found

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-10-27 17:05:59 +02:00
parent 827a90d7fc
commit 8761556bac
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -6,6 +6,7 @@ defmodule Mobilizon.Web.FeedController do
plug(:put_layout, false) plug(:put_layout, false)
action_fallback(Mobilizon.Web.FallbackController) action_fallback(Mobilizon.Web.FallbackController)
alias Mobilizon.Config alias Mobilizon.Config
require Logger
@spec instance(Plug.Conn.t(), map()) :: Plug.Conn.t() @spec instance(Plug.Conn.t(), map()) :: Plug.Conn.t()
def instance(conn, %{"format" => format}) do def instance(conn, %{"format" => format}) do
@ -45,8 +46,8 @@ defmodule Mobilizon.Web.FeedController do
@spec return_data(Plug.Conn.t(), String.t(), String.t(), String.t()) :: @spec return_data(Plug.Conn.t(), String.t(), String.t(), String.t()) ::
Plug.Conn.t() | {:error, :not_found} Plug.Conn.t() | {:error, :not_found}
defp return_data(conn, "atom", type, filename) do defp return_data(conn, "atom", key, filename) do
case Cachex.fetch(:feed, type) do case Cachex.fetch(:feed, key) do
{status, data} when status in [:commit, :ok] -> {status, data} when status in [:commit, :ok] ->
conn conn
|> put_resp_content_type("application/atom+xml") |> put_resp_content_type("application/atom+xml")
@ -56,13 +57,21 @@ defmodule Mobilizon.Web.FeedController do
) )
|> send_resp(200, data) |> send_resp(200, data)
_err -> # No need to log these two
{:ignore, :actor_not_found} ->
{:error, :not_found}
{:ignore, :actor_not_public} ->
{:error, :not_found}
err ->
Logger.warn("Unable to find feed data cached for key #{key}, returned #{inspect(err)}")
{:error, :not_found} {:error, :not_found}
end end
end end
defp return_data(conn, "ics", type, filename) do defp return_data(conn, "ics", key, filename) do
case Cachex.fetch(:ics, type) do case Cachex.fetch(:ics, key) do
{status, data} when status in [:commit, :ok] -> {status, data} when status in [:commit, :ok] ->
conn conn
|> put_resp_content_type("text/calendar") |> put_resp_content_type("text/calendar")
@ -72,7 +81,15 @@ defmodule Mobilizon.Web.FeedController do
) )
|> send_resp(200, data) |> send_resp(200, data)
_ -> # No need to log these two
{:ignore, :actor_not_found} ->
{:error, :not_found}
{:ignore, :actor_not_public} ->
{:error, :not_found}
err ->
Logger.warn("Unable to find feed data cached for key #{key}, returned #{inspect(err)}")
{:error, :not_found} {:error, :not_found}
end end
end end