From c464355d1ac7f9558aa50f7038035b9a47614822 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 5 May 2018 11:15:57 +0200 Subject: Idempotency: Use special cache, keep for 6 hours. --- lib/pleroma/application.ex | 12 ++++++++++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 89826f515..e1e3bcd63 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -23,6 +23,18 @@ defmodule Pleroma.Application do limit: 2500 ] ]), + worker( + Cachex, + [ + :idempotency_cache, + [ + default_ttl: :timer.seconds(6 * 60 * 60), + ttl_interval: :timer.seconds(60), + limit: 2500 + ] + ], + id: :cachex_idem + ), worker(Pleroma.Web.Federator, []), worker(Pleroma.Gopher.Server, []), worker(Pleroma.Stats, []) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index bbd16482a..2b4e9e72b 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -283,13 +283,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, activity} = Cachex.get!( - :user_cache, - "idem:#{idempotency_key}", + :idempotency_cache, + idempotency_key, fallback: fn _ -> CommonAPI.post(user, params) end ) - Cachex.expire(:user_cache, "idem:#{idempotency_key}", :timer.seconds(5 * 60)) - render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) end -- cgit v1.2.3