mix/deps: upgrade cachex to 4.x
This commit is contained in:
parent
d1050dab76
commit
534124cae2
15 changed files with 39 additions and 31 deletions
|
|
@ -59,6 +59,8 @@ def get_cached_scrubbed_html_for_activity(
|
|||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
add_cache_key_for(activity.id, key)
|
||||
|
||||
# callback already produces :commit or :ignore tuples
|
||||
HTML.ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback)
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -151,74 +151,74 @@ defp cachex_children do
|
|||
build_cachex(
|
||||
"user",
|
||||
expiration: expiration(default: 25_000, interval: 1000),
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"object",
|
||||
expiration: expiration(default: 25_000, interval: 1000),
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"rich_media",
|
||||
expiration: expiration(default: :timer.minutes(120)),
|
||||
limit: 5000
|
||||
hooks: [cachex_sched_limit(5000)]
|
||||
),
|
||||
build_cachex(
|
||||
"scrubber",
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"scrubber_management",
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"idempotency",
|
||||
expiration:
|
||||
expiration(default: :timer.seconds(6 * 60 * 60), interval: :timer.seconds(60)),
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500, [], frequency: :timer.minutes(1))]
|
||||
),
|
||||
build_cachex(
|
||||
"web_resp",
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"emoji_packs",
|
||||
expiration: expiration(default: :timer.seconds(5 * 60), interval: :timer.seconds(60)),
|
||||
limit: 10
|
||||
hooks: [cachex_sched_limit(10)]
|
||||
),
|
||||
build_cachex(
|
||||
"failed_proxy_url",
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"banned_urls",
|
||||
expiration: expiration(default: :timer.hours(24 * 30)),
|
||||
limit: 5_000
|
||||
hooks: [cachex_sched_limit(5_000, [], frequency: :timer.minutes(5))]
|
||||
),
|
||||
build_cachex(
|
||||
"translations",
|
||||
expiration: expiration(default: :timer.hours(24 * 30)),
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"instances",
|
||||
expiration: expiration(default: :timer.hours(24), interval: 1000),
|
||||
limit: 2500
|
||||
hooks: [cachex_sched_limit(2500)]
|
||||
),
|
||||
build_cachex(
|
||||
"rel_me",
|
||||
expiration: expiration(default: :timer.hours(24 * 30)),
|
||||
limit: 300
|
||||
hooks: [cachex_sched_limit(300, [], frequency: :timer.minutes(1))]
|
||||
),
|
||||
build_cachex(
|
||||
"host_meta",
|
||||
expiration: expiration(default: :timer.minutes(120)),
|
||||
limit: 5000
|
||||
hooks: [cachex_sched_limit(5000, [], frequency: :timer.minutes(1))]
|
||||
),
|
||||
build_cachex(
|
||||
"http_backoff",
|
||||
expiration: expiration(default: :timer.hours(24 * 30)),
|
||||
limit: 10000
|
||||
hooks: [cachex_sched_limit(10_000, [], frequency: :timer.minutes(5))]
|
||||
)
|
||||
]
|
||||
end
|
||||
|
|
@ -226,6 +226,9 @@ defp cachex_children do
|
|||
defp seconds_valid_interval,
|
||||
do: :timer.seconds(Config.get!([Pleroma.Captcha, :seconds_valid]))
|
||||
|
||||
defp cachex_sched_limit(limit, prune_opts \\ [], sched_opts \\ []),
|
||||
do: hook(module: Cachex.Limit.Scheduled, args: {limit, prune_opts, sched_opts})
|
||||
|
||||
@spec build_cachex(String.t(), keyword()) :: map()
|
||||
def build_cachex(type, opts),
|
||||
do: %{
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ defp validate_usage(token) do
|
|||
|
||||
defp mark_captcha_as_used(token) do
|
||||
ttl = seconds_valid() |> :timer.seconds()
|
||||
@cachex.put(:used_captcha_cache, token, true, ttl: ttl)
|
||||
@cachex.put(:used_captcha_cache, token, true, expire: ttl)
|
||||
end
|
||||
|
||||
defp method, do: Pleroma.Config.get!([__MODULE__, :method])
|
||||
|
|
|
|||
|
|
@ -464,7 +464,7 @@ defp create_archive_and_cache(pack, hash) do
|
|||
# if pack.json MD5 changes, the cache is not valid anymore
|
||||
%{hash: hash, pack_data: result},
|
||||
# Add a minute to cache time for every file in the pack
|
||||
ttl: overall_ttl
|
||||
expire: overall_ttl
|
||||
)
|
||||
|
||||
result
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ defp check_backoff({:ok, env}, host) do
|
|||
log_ratelimit(status, host, timestamp)
|
||||
ttl = Timex.diff(timestamp, DateTime.utc_now(), :seconds)
|
||||
# we will cache the host for 5 minutes
|
||||
@cachex.put(@backoff_cache, host, true, ttl: ttl)
|
||||
@cachex.put(@backoff_cache, host, true, expire: ttl)
|
||||
{:error, :ratelimit}
|
||||
|
||||
_ ->
|
||||
|
|
|
|||
|
|
@ -366,6 +366,6 @@ defp track_failed_url(url, error, opts) do
|
|||
nil
|
||||
end
|
||||
|
||||
@cachex.put(:failed_proxy_url_cache, url, true, ttl: ttl)
|
||||
@cachex.put(:failed_proxy_url_cache, url, true, expire: ttl)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -270,13 +270,13 @@ def unquote(:"#{outgoing_relation_target}_ap_ids")(user, restrict_deactivated? \
|
|||
|
||||
def cached_blocked_users_ap_ids(user) do
|
||||
@cachex.fetch!(:user_cache, "blocked_users_ap_ids:#{user.ap_id}", fn _ ->
|
||||
blocked_users_ap_ids(user)
|
||||
{:commit, blocked_users_ap_ids(user)}
|
||||
end)
|
||||
end
|
||||
|
||||
def cached_muted_users_ap_ids(user) do
|
||||
@cachex.fetch!(:user_cache, "muted_users_ap_ids:#{user.ap_id}", fn _ ->
|
||||
muted_users_ap_ids(user)
|
||||
{:commit, muted_users_ap_ids(user)}
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
@ -1162,7 +1162,7 @@ def get_user_friends_ap_ids(user) do
|
|||
@spec get_cached_user_friends_ap_ids(User.t()) :: [String.t()]
|
||||
def get_cached_user_friends_ap_ids(user) do
|
||||
@cachex.fetch!(:user_cache, "friends_ap_ids:#{user.ap_id}", fn _ ->
|
||||
get_user_friends_ap_ids(user)
|
||||
{:commit, get_user_friends_ap_ids(user)}
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def index(%{assigns: %{user: _}} = conn, params) do
|
|||
|
||||
defp fetch_entries(params) do
|
||||
MediaProxy.cache_table()
|
||||
|> @cachex.stream!(Cachex.Query.create(true, :key))
|
||||
|> @cachex.stream!(Cachex.Query.build(output: :key))
|
||||
|> filter_entries(params[:query])
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ defp get_languages do
|
|||
|
||||
@cachex.fetch!(:translations_cache, "languages:#{module}}", fn _ ->
|
||||
with {:ok, source_languages, dest_languages} <- module.languages() do
|
||||
{:ok, source_languages, dest_languages}
|
||||
{:commit, {:ok, source_languages, dest_languages}}
|
||||
else
|
||||
{:error, err} -> {:ignore, {:error, err}}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -531,7 +531,7 @@ defp fetch_or_translate(status_id, text, source_language, target_language, trans
|
|||
value = translation_module.translate(text, source_language, target_language)
|
||||
|
||||
with {:ok, _, _} <- value do
|
||||
value
|
||||
{:commit, value}
|
||||
else
|
||||
_ -> {:ignore, value}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ defp cache_resp(conn, opts) do
|
|||
conn =
|
||||
unless opts[:tracking_fun] do
|
||||
if should_cache do
|
||||
@cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl)
|
||||
@cachex.put(:web_resp_cache, key, {content_type, body}, expire: ttl)
|
||||
end
|
||||
|
||||
conn
|
||||
|
|
@ -110,7 +110,9 @@ defp cache_resp(conn, opts) do
|
|||
tracking_fun_data = Map.get(conn.assigns, :tracking_fun_data, nil)
|
||||
|
||||
if should_cache do
|
||||
@cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data}, ttl: ttl)
|
||||
@cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data},
|
||||
expire: ttl
|
||||
)
|
||||
end
|
||||
|
||||
opts.tracking_fun.(conn, tracking_fun_data)
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ defp stream_update(%{"activity_id" => activity_id}) do
|
|||
defp warm_cache(key, val), do: @cachex.put(:rich_media_cache, key, val)
|
||||
|
||||
def negative_cache(key, ttl \\ :timer.minutes(30)) do
|
||||
@cachex.put(:rich_media_cache, key, nil, ttl: ttl)
|
||||
@cachex.put(:rich_media_cache, key, nil, expire: ttl)
|
||||
{:discard, :error}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
2
mix.exs
2
mix.exs
|
|
@ -136,7 +136,7 @@ defp deps do
|
|||
{:phoenix_html, "~> 4.0"},
|
||||
{:phoenix_html_helpers, "~> 1.0"},
|
||||
{:calendar, "~> 1.0"},
|
||||
{:cachex, "~> 3.6"},
|
||||
{:cachex, "~> 4.1"},
|
||||
{:tesla, "~> 1.7"},
|
||||
{:castore, "~> 1.0"},
|
||||
{:cowlib, "~> 2.12"},
|
||||
|
|
|
|||
3
mix.lock
3
mix.lock
|
|
@ -5,7 +5,7 @@
|
|||
"bcrypt_elixir": {:hex, :bcrypt_elixir, "3.3.2", "d50091e3c9492d73e17fc1e1619a9b09d6a5ef99160eb4d736926fd475a16ca3", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "471be5151874ae7931911057d1467d908955f93554f7a6cd1b7d804cac8cef53"},
|
||||
"benchee": {:hex, :benchee, "1.5.0", "4d812c31d54b0ec0167e91278e7de3f596324a78a096fd3d0bea68bb0c513b10", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.1", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "5b075393aea81b8ae74eadd1c28b1d87e8a63696c649d8293db7c4df3eb67535"},
|
||||
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
|
||||
"cachex": {:hex, :cachex, "3.6.0", "14a1bfbeee060dd9bec25a5b6f4e4691e3670ebda28c8ba2884b12fe30b36bf8", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "ebf24e373883bc8e0c8d894a63bbe102ae13d918f790121f5cfe6e485cc8e2e2"},
|
||||
"cachex": {:hex, :cachex, "4.1.1", "574c5cd28473db313a0a76aac8c945fe44191659538ca6a1e8946ec300b1a19f", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:ex_hash_ring, "~> 6.0", [hex: :ex_hash_ring, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "d6b7449ff98d6bb92dda58bd4fc3189cae9f99e7042054d669596f56dc503cd8"},
|
||||
"calendar": {:hex, :calendar, "1.0.0", "f52073a708528482ec33d0a171954ca610fe2bd28f1e871f247dc7f1565fa807", [:mix], [{:tzdata, "~> 0.1.201603 or ~> 0.5.20 or ~> 1.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "990e9581920c82912a5ee50e62ff5ef96da6b15949a2ee4734f935fdef0f0a6f"},
|
||||
"captcha": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git", "784605815756bbc1d7e313ff552840afb62e2c41", [branch: "master"]},
|
||||
"castore": {:hex, :castore, "1.0.16", "8a4f9a7c8b81cda88231a08fe69e3254f16833053b23fa63274b05cbc61d2a1e", [:mix], [], "hexpm", "33689203a0eaaf02fcd0e86eadfbcf1bd636100455350592e7e2628564022aaf"},
|
||||
|
|
@ -41,6 +41,7 @@
|
|||
"ex_aws_s3": {:hex, :ex_aws_s3, "2.5.8", "5ee7407bc8252121ad28fba936b3b293f4ecef93753962351feb95b8a66096fa", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "84e512ca2e0ae6a6c497036dff06d4493ffb422cfe476acc811d7c337c16691c"},
|
||||
"ex_const": {:hex, :ex_const, "0.3.0", "9d79516679991baf540ef445438eef1455ca91cf1a3c2680d8fb9e5bea2fe4de", [:mix], [], "hexpm", "76546322abb9e40ee4a2f454cf1c8a5b25c3672fa79bed1ea52c31e0d2428ca9"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.39.1", "e19d356a1ba1e8f8cfc79ce1c3f83884b6abfcb79329d435d4bbb3e97ccc286e", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "8abf0ed3e3ca87c0847dfc4168ceab5bedfe881692f1b7c45f4a11b232806865"},
|
||||
"ex_hash_ring": {:hex, :ex_hash_ring, "6.0.4", "bef9d2d796afbbe25ab5b5a7ed746e06b99c76604f558113c273466d52fa6d6b", [:mix], [], "hexpm", "89adabf31f7d3dfaa36802ce598ce918e9b5b33bae8909ac1a4d052e1e567d18"},
|
||||
"ex_machina": {:hex, :ex_machina, "2.8.0", "a0e847b5712065055ec3255840e2c78ef9366634d62390839d4880483be38abe", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "79fe1a9c64c0c1c1fab6c4fa5d871682cb90de5885320c187d117004627a7729"},
|
||||
"ex_syslogger": {:hex, :ex_syslogger, "2.1.0", "437dcf5cb4ba05116dd3a848555c683443ef90c4336fca4d336fd78e4614bcd3", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}, {:syslog, "~> 1.1.0", [hex: :syslog, repo: "hexpm", optional: false]}], "hexpm", "a7c4ca96aacc8290dc6b338dd0080b9ba4ec3a5b93665a8a614f8c2d8d7dee8e"},
|
||||
"excoveralls": {:hex, :excoveralls, "0.18.5", "e229d0a65982613332ec30f07940038fe451a2e5b29bce2a5022165f0c9b157e", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "523fe8a15603f86d64852aab2abe8ddbd78e68579c8525ae765facc5eae01562"},
|
||||
|
|
|
|||
|
|
@ -273,6 +273,6 @@ def expire_ttl(%{remote_ip: remote_ip} = _conn, bucket_name_root) do
|
|||
key_name = "ip::#{remote_ip |> Tuple.to_list() |> Enum.join(".")}"
|
||||
|
||||
{:ok, bucket_value} = Cachex.get(bucket_name, key_name)
|
||||
Cachex.put(bucket_name, key_name, bucket_value, ttl: -1)
|
||||
Cachex.put(bucket_name, key_name, bucket_value, expire: -1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue