aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/application.ex11
-rw-r--r--lib/pleroma/web/metadata.ex10
-rw-r--r--lib/pleroma/web/router.ex2
3 files changed, 22 insertions, 1 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index ad2797209..5f9518914 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -87,6 +87,17 @@ defmodule Pleroma.Application do
worker(
Cachex,
[
+ :metadata_cache,
+ [
+ limit: 2500,
+ default_ttl: :timer.minutes(15)
+ ]
+ ],
+ id: :cachex_metadata
+ ),
+ worker(
+ Cachex,
+ [
:idempotency_cache,
[
expiration:
diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex
index cf2b86aaa..a5a706b8f 100644
--- a/lib/pleroma/web/metadata.ex
+++ b/lib/pleroma/web/metadata.ex
@@ -2,6 +2,16 @@ defmodule Pleroma.Web.Metadata do
alias Phoenix.HTML
@parsers Pleroma.Config.get([:metadata, :providers], [])
+
+ def get_cached_tags(params) do
+ # I am unsure how well ETS works with big keys
+ key = :erlang.term_to_binary(params)
+
+ Cachex.fetch!(:metadata_cache, key, fn _key ->
+ {:commit, build_tags(params)}
+ end)
+ end
+
def build_tags(params) do
Enum.reduce(@parsers, "", fn parser, acc ->
rendered_html =
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 25e866c48..1ecd4aee1 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -534,7 +534,7 @@ defmodule Fallback.RedirectController do
def redirector_with_meta(conn, params) do
{:ok, index_content} = File.read(index_file_path())
- tags = Metadata.build_tags(params)
+ tags = Metadata.get_cached_tags(params)
response = String.replace(index_content, "<!--server-generated-meta-->", tags)
conn