diff options
author | rinpatch <rinpatch@sdf.org> | 2019-01-04 23:56:42 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-01-04 23:56:42 +0000 |
commit | ba17518a0aff404e265f4aebec1257912ad2750c (patch) | |
tree | 76f9f69b11fcfa24c1a67e311f779e1b7e083542 /lib | |
parent | bf5aaefbb56a8ff8ac4e43874dacd794f3deda84 (diff) | |
parent | 487c00d36dee1b975ffc8fca8f0a5bb5510f71a3 (diff) | |
download | pleroma-ba17518a0aff404e265f4aebec1257912ad2750c.tar.gz |
Merge branch 'feature/rich-media-cachex' into 'develop'
rich media: use cachex to avoid flooding remote servers
See merge request pleroma/pleroma!629
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/application.ex | 11 | ||||
-rw-r--r-- | lib/pleroma/web/rich_media/parser.ex | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index cb3e6b69b..ad2797209 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -66,6 +66,17 @@ defmodule Pleroma.Application do worker( Cachex, [ + :rich_media_cache, + [ + default_ttl: :timer.minutes(120), + limit: 5000 + ] + ], + id: :cachex_rich_media + ), + worker( + Cachex, + [ :scrubber_cache, [ limit: 2500 diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 477a38196..3746feaf6 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -1,7 +1,14 @@ 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() |