From 9b61df1fb64c49a4ad6277862d1405a27ad1c0da Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 12 Feb 2021 12:44:45 -0600 Subject: [PATCH] App is already preloaded into the token, so avoid an extra query --- .../web/mastodon_api/controllers/status_controller.ex | 6 ++++-- lib/pleroma/web/o_auth/app.ex | 10 ---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index ec3e79ea7..db3f248e5 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -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}) diff --git a/lib/pleroma/web/o_auth/app.ex b/lib/pleroma/web/o_auth/app.ex index 083b5ce09..382750010 100644 --- a/lib/pleroma/web/o_auth/app.ex +++ b/lib/pleroma/web/o_auth/app.ex @@ -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