forked from AkkomaGang/akkoma
App is already preloaded into the token, so avoid an extra query
This commit is contained in:
parent
bd3d0e8b57
commit
9b61df1fb6
2 changed files with 4 additions and 12 deletions
|
@ -21,6 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
|
|||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.ScheduledActivityView
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Web.Plugs.RateLimiter
|
||||
|
||||
|
@ -419,8 +420,9 @@ def bookmarks(%{assigns: %{user: user}} = conn, params) do
|
|||
)
|
||||
end
|
||||
|
||||
defp put_application(params, %{assigns: %{token: %{app_id: app_id}}} = _conn) do
|
||||
Map.put(params, :application, Pleroma.Web.OAuth.App.get_app_by_id(app_id))
|
||||
defp put_application(params, %{assigns: %{token: %Token{} = token}} = _conn) do
|
||||
%{client_name: client_name, website: website} = Repo.preload(token, :app).app
|
||||
Map.put(params, :application, %{name: client_name, website: website})
|
||||
end
|
||||
|
||||
defp put_application(params, _), do: Map.put(params, :application, %{name: "Web", website: nil})
|
||||
|
|
|
@ -146,14 +146,4 @@ def errors(changeset) do
|
|||
Map.put(acc, key, error)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue