rich media: disable cachex in test mode

This commit is contained in:
William Pitcock 2019-01-04 23:50:54 +00:00
parent 0964c207eb
commit 487c00d36d

View file

@ -1,14 +1,17 @@
defmodule Pleroma.Web.RichMedia.Parser do defmodule Pleroma.Web.RichMedia.Parser do
@parsers [Pleroma.Web.RichMedia.Parsers.OGP] @parsers [Pleroma.Web.RichMedia.Parsers.OGP]
def parse(url) do if Mix.env() == :test do
Cachex.fetch!(:rich_media_cache, url, fn _ -> def parse(url), do: parse_url(url)
else
def parse(url),
do: {:commit, Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end)}
end
defp parse_url(url) do
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
result = html |> maybe_parse() |> get_parsed_data() html |> maybe_parse() |> get_parsed_data()
{:commit, result}
end)
end end
defp maybe_parse(html) do defp maybe_parse(html) do