From f169de34544a12c174c454da59781a694b8c2387 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 1 May 2017 16:12:20 +0200 Subject: [PATCH] Cache objects in dev and prod. --- lib/pleroma/object.ex | 9 +++++++++ lib/pleroma/web/twitter_api/twitter_api.ex | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index a924c3199..168843bd9 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -14,6 +14,15 @@ def get_by_ap_id(ap_id) do where: fragment("? @> ?", object.data, ^%{id: ap_id})) end + def get_cached_by_ap_id(ap_id) do + if Mix.env == :test do + get_by_ap_id(ap_id) + else + key = "object:#{ap_id}" + Cachex.get!(:user_cache, key, fallback: fn(_) -> get_by_ap_id(ap_id) end) + end + end + def context_mapping(context) do %Object{data: %{"id" => context}} end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 85fac9146..941bacaa9 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -317,7 +317,7 @@ defp make_date do def context_to_conversation_id(context) do {:ok, id} = Repo.transaction(fn -> - with %Object{id: id} <- Object.get_by_ap_id(context) do + with %Object{id: id} <- Object.get_cached_by_ap_id(context) do id else _e -> changeset = Object.context_mapping(context)