cache ap_id in id instead of caching user two times

This commit is contained in:
rinpatch 2019-01-16 17:44:08 +03:00
parent 76f80940da
commit 5a08dee379

View file

@ -445,7 +445,15 @@ def get_cached_by_ap_id(ap_id) do
def get_cached_by_id(id) do def get_cached_by_id(id) do
key = "id:#{id}" key = "id:#{id}"
Cachex.fetch!(:user_cache, key, fn _ -> get_by_id(id) end)
ap_id =
Cachex.fetch!(:user_cache, key, fn _ ->
user = get_by_id(id)
Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
{:commit, user.ap_id}
end)
get_cached_by_ap_id(ap_id)
end end
def get_cached_by_nickname(nickname) do def get_cached_by_nickname(nickname) do