rich media: use cachex to avoid flooding remote servers
This commit is contained in:
parent
4258dd8633
commit
0964c207eb
@ -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
|
||||||
|
@ -2,9 +2,13 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
|||||||
@parsers [Pleroma.Web.RichMedia.Parsers.OGP]
|
@parsers [Pleroma.Web.RichMedia.Parsers.OGP]
|
||||||
|
|
||||||
def parse(url) do
|
def parse(url) do
|
||||||
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
|
Cachex.fetch!(:rich_media_cache, url, fn _ ->
|
||||||
|
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
|
||||||
|
|
||||||
html |> maybe_parse() |> get_parsed_data()
|
result = html |> maybe_parse() |> get_parsed_data()
|
||||||
|
|
||||||
|
{:commit, result}
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_parse(html) do
|
defp maybe_parse(html) do
|
||||||
|
Loading…
Reference in New Issue
Block a user