Merge branch 'feature/rich-media-cachex' into 'develop'
rich media: use cachex to avoid flooding remote servers See merge request pleroma/pleroma!629
This commit is contained in:
commit
ba17518a0a
@ -66,6 +66,17 @@ defmodule Pleroma.Application do
|
|||||||
worker(
|
worker(
|
||||||
Cachex,
|
Cachex,
|
||||||
[
|
[
|
||||||
|
:rich_media_cache,
|
||||||
|
[
|
||||||
|
default_ttl: :timer.minutes(120),
|
||||||
|
limit: 5000
|
||||||
|
]
|
||||||
|
],
|
||||||
|
id: :cachex_rich_media
|
||||||
|
),
|
||||||
|
worker(
|
||||||
|
Cachex,
|
||||||
|
[
|
||||||
:scrubber_cache,
|
:scrubber_cache,
|
||||||
[
|
[
|
||||||
limit: 2500
|
limit: 2500
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
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
|
||||||
|
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)
|
||||||
|
|
||||||
html |> maybe_parse() |> get_parsed_data()
|
html |> maybe_parse() |> get_parsed_data()
|
||||||
|
Loading…
Reference in New Issue
Block a user