From c747260989fdba32a8f319f88f0840c811ff8b50 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 29 Feb 2020 22:04:09 +0300 Subject: [PATCH] [#2250] Tiny refactoring per merge request review. --- lib/pleroma/plugs/rate_limiter/rate_limiter.ex | 6 ++++-- test/plugs/rate_limiter_test.exs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/plugs/rate_limiter/rate_limiter.ex b/lib/pleroma/plugs/rate_limiter/rate_limiter.ex index 3a27d6eb7..9c362a392 100644 --- a/lib/pleroma/plugs/rate_limiter/rate_limiter.ex +++ b/lib/pleroma/plugs/rate_limiter/rate_limiter.ex @@ -121,6 +121,8 @@ defmodule Pleroma.Plugs.RateLimiter do localhost_or_socket and remote_ip_disabled end + @inspect_bucket_not_found {:error, :not_found} + def inspect_bucket(conn, bucket_name_root, plug_opts) do with %{name: _} = action_settings <- action_settings(plug_opts) do action_settings = incorporate_conn_info(action_settings, conn) @@ -130,7 +132,7 @@ defmodule Pleroma.Plugs.RateLimiter do case Cachex.get(bucket_name, key_name) do {:error, :no_cache} -> - {:err, :not_found} + @inspect_bucket_not_found {:ok, nil} -> {0, limit} @@ -139,7 +141,7 @@ defmodule Pleroma.Plugs.RateLimiter do {value, limit - value} end else - _ -> {:err, :not_found} + _ -> @inspect_bucket_not_found end end diff --git a/test/plugs/rate_limiter_test.exs b/test/plugs/rate_limiter_test.exs index c0630c039..104d67611 100644 --- a/test/plugs/rate_limiter_test.exs +++ b/test/plugs/rate_limiter_test.exs @@ -109,7 +109,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do RateLimiter.call(conn, plug_opts) assert {1, 4} = RateLimiter.inspect_bucket(conn, base_bucket_name, plug_opts) - assert {:err, :not_found} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts) + assert {:error, :not_found} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts) end test "`params` option allows different queries to be tracked independently" do