Commit f169de34 authored by lain's avatar lain
Browse files

Cache objects in dev and prod.

parent b9d1fc05
......@@ -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
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment