diff options
author | rinpatch <rinpatch@sdf.org> | 2019-01-16 10:26:01 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-01-16 10:26:01 +0300 |
commit | 70b2bb6eded5597bd768d7dc8754c2c994561aee (patch) | |
tree | 333a9bbe44e8e5e188bc109a65698a3e2afab15b /lib | |
parent | dd1432d6955a72b8483717978d61a505e0608bbc (diff) | |
download | pleroma-70b2bb6eded5597bd768d7dc8754c2c994561aee.tar.gz |
add caching
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/application.ex | 11 | ||||
-rw-r--r-- | lib/pleroma/web/metadata.ex | 10 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 2 |
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 |