Cache objects in dev and prod.

This commit is contained in:
Roger Braun 2017-05-01 16:12:20 +02:00
parent b9d1fc05b2
commit f169de3454
2 changed files with 10 additions and 1 deletions

View File

@ -14,6 +14,15 @@ def get_by_ap_id(ap_id) do
where: fragment("? @> ?", object.data, ^%{id: ap_id})) where: fragment("? @> ?", object.data, ^%{id: ap_id}))
end 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 def context_mapping(context) do
%Object{data: %{"id" => context}} %Object{data: %{"id" => context}}
end end

View File

@ -317,7 +317,7 @@ defp make_date do
def context_to_conversation_id(context) do def context_to_conversation_id(context) do
{:ok, id} = Repo.transaction(fn -> {: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 id
else _e -> else _e ->
changeset = Object.context_mapping(context) changeset = Object.context_mapping(context)