summaryrefslogtreecommitdiff
path: root/lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-11-12 12:34:48 +0000
committerrinpatch <rinpatch@sdf.org>2020-11-12 12:34:48 +0000
commit1172844ed18d94d84724dc6f11c6e9f72e0ba6ec (patch)
tree7d48a259e08856ab6db0eba255f20c0c19410463 /lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex
parenta0f5e8b27edbe2224d9c2c3997ad5b8ea484244b (diff)
parentb4c6b262d6dc12362f0014a864e8aed6c727c39c (diff)
Merge branch 'release/2.2.0' into 'stable'v2.2.0
Release/2.2.0 See merge request pleroma/secteam/pleroma!19
Diffstat (limited to 'lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex')
-rw-r--r--lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex50
1 files changed, 0 insertions, 50 deletions
diff --git a/lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex b/lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex
deleted file mode 100644
index 884268d96..000000000
--- a/lib/pleroma/plugs/rate_limiter/limiter_supervisor.ex
+++ /dev/null
@@ -1,50 +0,0 @@
-defmodule Pleroma.Plugs.RateLimiter.LimiterSupervisor do
- use DynamicSupervisor
-
- import Cachex.Spec
-
- def start_link(init_arg) do
- DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
- end
-
- def add_or_return_limiter(limiter_name, expiration) do
- result =
- DynamicSupervisor.start_child(
- __MODULE__,
- %{
- id: String.to_atom("rl_#{limiter_name}"),
- start:
- {Cachex, :start_link,
- [
- limiter_name,
- [
- expiration:
- expiration(
- default: expiration,
- interval: check_interval(expiration),
- lazy: true
- )
- ]
- ]}
- }
- )
-
- case result do
- {:ok, _pid} = result -> result
- {:error, {:already_started, pid}} -> {:ok, pid}
- _ -> result
- end
- end
-
- @impl true
- def init(_init_arg) do
- DynamicSupervisor.init(strategy: :one_for_one)
- end
-
- defp check_interval(exp) do
- (exp / 2)
- |> Kernel.trunc()
- |> Kernel.min(5000)
- |> Kernel.max(1)
- end
-end