Use cache for user info data.
authorRoger Braun <roger@rogerbraun.net>
Sun, 30 Apr 2017 08:04:54 +0000 (10:04 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 30 Apr 2017 08:04:54 +0000 (10:04 +0200)
Later these should be persisted in the user.

lib/pleroma/user.ex
lib/pleroma/web/twitter_api/representers/user_representer.ex

index 9b7912c5beb0779aae9097e666984e6bcb656edb..cd61046802bfbfcbe1bfaaa0b936b87b04012d24 100644 (file)
@@ -122,4 +122,9 @@ defmodule Pleroma.User 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
index ab7d6d353a7476357703f18631f53d3418ef043a..29c7451f461f5d47687ed05d17b1dfd5cd4ecab4 100644 (file)
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
       false
     end
 
-    user_info = User.user_info(user)
+    user_info = User.get_cached_user_info(user)
 
     map = %{
       "id" => user.id,