diff options
author | William Pitcock <nenolod@dereferenced.org> | 2019-01-04 23:23:47 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2019-01-04 23:32:01 +0000 |
commit | 0964c207eb184696355a2d8efd9d671dcc23ce66 (patch) | |
tree | 1d34af5bf07e0761eca2e428766763f1a34f3d2e /lib | |
parent | 4258dd8633407587ca1f3dfe275afa6a91be9197 (diff) | |
download | pleroma-0964c207eb184696355a2d8efd9d671dcc23ce66.tar.gz |
rich media: use cachex to avoid flooding remote servers
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/application.ex | 11 | ||||
-rw-r--r-- | lib/pleroma/web/rich_media/parser.ex | 8 |
2 files changed, 17 insertions, 2 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..b88ed5371 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -2,9 +2,13 @@ defmodule Pleroma.Web.RichMedia.Parser do @parsers [Pleroma.Web.RichMedia.Parsers.OGP] 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 defp maybe_parse(html) do |