From ffc604a2c2d963b63e6cd13d0ee7cc9024f632a4 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 30 Apr 2017 10:04:54 +0200 Subject: [PATCH] Use cache for user info data. Later these should be persisted in the user. --- lib/pleroma/user.ex | 5 +++++ lib/pleroma/web/twitter_api/representers/user_representer.ex | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 9b7912c5b..cd6104680 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -122,4 +122,9 @@ def get_cached_by_nickname(nickname) do key = "nickname:#{nickname}" Cachex.get!(:user_cache, key, fallback: fn(_) -> Repo.get_by(User, nickname: nickname) end) end + + def get_cached_user_info(user) do + key = "user_info:#{user.id}" + Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end) + end end diff --git a/lib/pleroma/web/twitter_api/representers/user_representer.ex b/lib/pleroma/web/twitter_api/representers/user_representer.ex index ab7d6d353..29c7451f4 100644 --- a/lib/pleroma/web/twitter_api/representers/user_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/user_representer.ex @@ -11,7 +11,7 @@ def to_map(user, opts) do false end - user_info = User.user_info(user) + user_info = User.get_cached_user_info(user) map = %{ "id" => user.id,