[#2250] Tiny refactoring per merge request review.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 29 Feb 2020 19:04:09 +0000 (22:04 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 29 Feb 2020 19:04:09 +0000 (22:04 +0300)
lib/pleroma/plugs/rate_limiter/rate_limiter.ex
test/plugs/rate_limiter_test.exs

index 3a27d6eb7e2fbfae008a4282dcbcf885c6780e31..9c362a392c3663b0d542310e04f3b1d5df7931f3 100644 (file)
@@ -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
 
index c0630c0393808dd0e17a46a9e03dc6594cc29363..104d67611bff9028c8ce191fc027b90694c6d819 100644 (file)
@@ -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