Correct ttl syntax for new cachex

This commit is contained in:
Floatingghost 2024-04-26 19:05:12 +01:00
parent 3c384c1b76
commit ec7e9da734
2 changed files with 4 additions and 7 deletions

View file

@ -49,7 +49,7 @@ defmodule Pleroma.HTTP.Backoff do
timestamp = next_backoff_timestamp(env) timestamp = next_backoff_timestamp(env)
ttl = Timex.diff(timestamp, DateTime.utc_now(), :seconds) ttl = Timex.diff(timestamp, DateTime.utc_now(), :seconds)
# we will cache the host for 5 minutes # we will cache the host for 5 minutes
@cachex.put(@backoff_cache, host, true, ttl) @cachex.put(@backoff_cache, host, true, ttl: ttl)
{:error, :ratelimit} {:error, :ratelimit}
_ -> _ ->

View file

@ -17,8 +17,7 @@ defmodule Pleroma.HTTP.BackoffTest do
test "should return {:error, env} when rate limited" do test "should return {:error, env} when rate limited" do
# Shove a value into the cache to simulate a rate limit # Shove a value into the cache to simulate a rate limit
Cachex.put(@backoff_cache, "akkoma.dev", true) Cachex.put(@backoff_cache, "akkoma.dev", true)
assert {:error, env} = Backoff.get("https://akkoma.dev/api/v1/instance") assert {:error, :ratelimit} = Backoff.get("https://akkoma.dev/api/v1/instance")
assert env.status == 429
end end
test "should insert a value into the cache when rate limited" do test "should insert a value into the cache when rate limited" do
@ -27,8 +26,7 @@ defmodule Pleroma.HTTP.BackoffTest do
{:ok, %Tesla.Env{status: 429, body: "Rate limited"}} {:ok, %Tesla.Env{status: 429, body: "Rate limited"}}
end) end)
assert {:error, env} = Backoff.get("https://ratelimited.dev/api/v1/instance") assert {:error, :ratelimit} = Backoff.get("https://ratelimited.dev/api/v1/instance")
assert env.status == 429
assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev") assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev")
end end
@ -46,8 +44,7 @@ defmodule Pleroma.HTTP.BackoffTest do
}} }}
end) end)
assert {:error, env} = Backoff.get("https://ratelimited.dev/api/v1/instance") assert {:error, :ratelimit} = Backoff.get("https://ratelimited.dev/api/v1/instance")
assert env.status == 429
assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev") assert {:ok, true} = Cachex.get(@backoff_cache, "ratelimited.dev")
end end
end end