Get users fresh, might so we don't make new keys all the time.

This commit is contained in:
Roger Braun 2017-04-30 15:05:16 +02:00
parent bb1d08a47c
commit a173fb9e41
2 changed files with 5 additions and 1 deletions

View File

@ -123,6 +123,10 @@ def get_cached_by_nickname(nickname) do
Cachex.get!(:user_cache, key, fallback: fn(_) -> Repo.get_by(User, nickname: nickname) end) Cachex.get!(:user_cache, key, fallback: fn(_) -> Repo.get_by(User, nickname: nickname) end)
end end
def get_cached_by_nickname(nickname) do
Repo.get_by(User, nickname: nickname)
end
def get_cached_user_info(user) do def get_cached_user_info(user) do
key = "user_info:#{user.id}" key = "user_info:#{user.id}"
Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end) Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end)

View File

@ -20,7 +20,7 @@ def webfinger(resource) do
regex = ~r/(acct:)?(?<username>\w+)@#{host}/ regex = ~r/(acct:)?(?<username>\w+)@#{host}/
case Regex.named_captures(regex, resource) do case Regex.named_captures(regex, resource) do
%{"username" => username} -> %{"username" => username} ->
user = User.get_cached_by_nickname(username) user = User.get_by_nickname(username)
{:ok, represent_user(user)} {:ok, represent_user(user)}
_ -> nil _ -> nil
end end