Merge branch 'fix/oauth-token-user-caching' into 'develop'

OAuthPlug: use user cache instead of joining

See merge request pleroma/pleroma!3734
This commit is contained in:
tusooa 2022-08-24 15:23:20 +00:00
commit 85c1e1ff4d

View file

@ -47,15 +47,17 @@ defmodule Pleroma.Web.Plugs.OAuthPlug do
#
@spec fetch_user_and_token(String.t()) :: {:ok, User.t(), Token.t()} | nil
defp fetch_user_and_token(token) do
query =
token_query =
from(t in Token,
where: t.token == ^token,
join: user in assoc(t, :user),
preload: [user: user]
where: t.token == ^token
)
with %Token{user: user} = token_record <- Repo.one(query) do
with %Token{user_id: user_id} = token_record <- Repo.one(token_query),
false <- is_nil(user_id),
%User{} = user <- User.get_cached_by_id(user_id) do
{:ok, user, token_record}
else
_ -> nil
end
end