Commit ba17518a authored by rinpatch's avatar rinpatch
Browse files

Merge branch 'feature/rich-media-cachex' into 'develop'

rich media: use cachex to avoid flooding remote servers

See merge request !629
parents bf5aaefb 487c00d3
Pipeline #6009 passed with stages
in 3 minutes and 16 seconds
......@@ -63,6 +63,17 @@ def start(_type, _args) do
],
id: :cachex_object
),
worker(
Cachex,
[
:rich_media_cache,
[
default_ttl: :timer.minutes(120),
limit: 5000
]
],
id: :cachex_rich_media
),
worker(
Cachex,
[
......
defmodule Pleroma.Web.RichMedia.Parser do
@parsers [Pleroma.Web.RichMedia.Parsers.OGP]
def parse(url) do
if Mix.env() == :test do
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)
html |> maybe_parse() |> get_parsed_data()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment