X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fcaptcha%2Fcaptcha.ex;h=133a9fd68cf67a73a79e5c2704bc12d4b341626a;hb=1b1e92866742e75de84201b079ffee48c769886e;hp=df33406ee7777f0235ee34db0ffd60293d6b8848;hpb=b5518da90468ab1cde40593695d75f3d72d66783;p=akkoma diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index df33406ee..133a9fd68 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Captcha do use GenServer @@ -14,6 +18,10 @@ defmodule Pleroma.Captcha do ets_name = Module.concat(method(), Ets) ^ets_name = :ets.new(Module.concat(method(), Ets), @ets_options) + # Clean up old captchas every few minutes + seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) + Process.send_after(self(), :cleanup, 1000 * seconds_retained) + {:ok, nil} end @@ -47,5 +55,16 @@ defmodule Pleroma.Captcha do {:reply, method().validate(token, captcha), state} end + @doc false + def handle_info(:cleanup, state) do + :ok = method().cleanup() + + seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) + # Schedule the next clenup + Process.send_after(self(), :cleanup, 1000 * seconds_retained) + + {:noreply, state} + end + defp method, do: Pleroma.Config.get!([__MODULE__, :method]) end