mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 11:19:19 +00:00
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
2 changed files with 19 additions and 1 deletions
|
@ -63,6 +63,17 @@ defmodule Pleroma.Application do
|
||||||
],
|
],
|
||||||
id: :cachex_object
|
id: :cachex_object
|
||||||
),
|
),
|
||||||
|
worker(
|
||||||
|
Cachex,
|
||||||
|
[
|
||||||
|
:rich_media_cache,
|
||||||
|
[
|
||||||
|
default_ttl: :timer.minutes(120),
|
||||||
|
limit: 5000
|
||||||
|
]
|
||||||
|
],
|
||||||
|
id: :cachex_rich_media
|
||||||
|
),
|
||||||
worker(
|
worker(
|
||||||
Cachex,
|
Cachex,
|
||||||
[
|
[
|
||||||
|
|
|
@ -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 a new issue