App is already preloaded into the token, so avoid an extra query

This commit is contained in:
Mark Felder 2021-02-12 12:44:45 -06:00
parent bd3d0e8b57
commit 9b61df1fb6
2 changed files with 4 additions and 12 deletions

View File

@ -21,6 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.ScheduledActivityView alias Pleroma.Web.MastodonAPI.ScheduledActivityView
alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.Plugs.RateLimiter alias Pleroma.Web.Plugs.RateLimiter
@ -419,8 +420,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
) )
end end
defp put_application(params, %{assigns: %{token: %{app_id: app_id}}} = _conn) do defp put_application(params, %{assigns: %{token: %Token{} = token}} = _conn) do
Map.put(params, :application, Pleroma.Web.OAuth.App.get_app_by_id(app_id)) %{client_name: client_name, website: website} = Repo.preload(token, :app).app
Map.put(params, :application, %{name: client_name, website: website})
end end
defp put_application(params, _), do: Map.put(params, :application, %{name: "Web", website: nil}) defp put_application(params, _), do: Map.put(params, :application, %{name: "Web", website: nil})

View File

@ -146,14 +146,4 @@ defmodule Pleroma.Web.OAuth.App do
Map.put(acc, key, error) Map.put(acc, key, error)
end) end)
end end
@spec get_app_by_id(pos_integer()) :: {:ok, map()}
def get_app_by_id(app_id) do
query =
__MODULE__
|> where([a], a.id == ^app_id)
|> select([a], %{name: a.client_name, website: a.website})
Repo.one!(query)
end
end end