Add debug logs to timeline rendering to assist debugging
This commit is contained in:
parent
d85d1e128a
commit
66d162bb9e
4 changed files with 39 additions and 4 deletions
|
@ -284,7 +284,6 @@ defmodule Pleroma.Activity do
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@spec create_by_id_with_object(String.t()) :: t() | nil
|
@spec create_by_id_with_object(String.t()) :: t() | nil
|
||||||
def create_by_id_with_object(id) do
|
def create_by_id_with_object(id) do
|
||||||
get_by_id_with_opts(id, preload: [:object], filter: [type: "Create"])
|
get_by_id_with_opts(id, preload: [:object], filter: [type: "Create"])
|
||||||
|
|
|
@ -374,7 +374,7 @@ defmodule Pleroma.User do
|
||||||
do_optional_url(user.banner, "#{Endpoint.url()}/images/banner.png", options)
|
do_optional_url(user.banner, "#{Endpoint.url()}/images/banner.png", options)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_optional_url(field, default, options \\ []) do
|
defp do_optional_url(field, default, options) do
|
||||||
case field do
|
case field do
|
||||||
%{"url" => [%{"href" => href} | _]} when is_binary(href) ->
|
%{"url" => [%{"href" => href} | _]} when is_binary(href) ->
|
||||||
href
|
href
|
||||||
|
|
|
@ -37,10 +37,16 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
when action in [:public, :hashtag, :bubble]
|
when action in [:public, :hashtag, :bubble]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.TimelineOperation
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.TimelineOperation
|
||||||
|
|
||||||
# GET /api/v1/timelines/home
|
# GET /api/v1/timelines/home
|
||||||
def home(%{assigns: %{user: user}} = conn, params) do
|
def home(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
%{nickname: nickname} = user
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.home: #{nickname}")
|
||||||
|
|
||||||
followed_hashtags =
|
followed_hashtags =
|
||||||
user
|
user
|
||||||
|> User.followed_hashtags()
|
|> User.followed_hashtags()
|
||||||
|
@ -58,11 +64,15 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|> Map.put(:followed_hashtags, followed_hashtags)
|
|> Map.put(:followed_hashtags, followed_hashtags)
|
||||||
|> Map.delete(:local)
|
|> Map.delete(:local)
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.home: #{nickname} - fetching activities")
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
[user.ap_id | User.following(user)]
|
[user.ap_id | User.following(user)]
|
||||||
|> ActivityPub.fetch_activities(params)
|
|> ActivityPub.fetch_activities(params)
|
||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.home: #{nickname} - rendering")
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(activities)
|
|> add_link_headers(activities)
|
||||||
|> render("index.json",
|
|> render("index.json",
|
||||||
|
@ -75,6 +85,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|
|
||||||
# GET /api/v1/timelines/direct
|
# GET /api/v1/timelines/direct
|
||||||
def direct(%{assigns: %{user: user}} = conn, params) do
|
def direct(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
Logger.debug("TimelineController.direct: #{user.nickname}")
|
||||||
|
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|> Map.put(:type, "Create")
|
|> Map.put(:type, "Create")
|
||||||
|
@ -82,11 +94,15 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|> Map.put(:user, user)
|
|> Map.put(:user, user)
|
||||||
|> Map.put(:visibility, "direct")
|
|> Map.put(:visibility, "direct")
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.direct: #{user.nickname} - fetching activities")
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
[user.ap_id]
|
[user.ap_id]
|
||||||
|> ActivityPub.fetch_activities_query(params)
|
|> ActivityPub.fetch_activities_query(params)
|
||||||
|> Pagination.fetch_paginated(params)
|
|> Pagination.fetch_paginated(params)
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.direct: #{user.nickname} - rendering")
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(activities)
|
|> add_link_headers(activities)
|
||||||
|> render("index.json",
|
|> render("index.json",
|
||||||
|
@ -102,6 +118,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|
|
||||||
# GET /api/v1/timelines/public
|
# GET /api/v1/timelines/public
|
||||||
def public(%{assigns: %{user: user}} = conn, params) do
|
def public(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
Logger.debug("TimelineController.public")
|
||||||
local_only = params[:local]
|
local_only = params[:local]
|
||||||
timeline_type = if local_only, do: :local, else: :federated
|
timeline_type = if local_only, do: :local, else: :federated
|
||||||
|
|
||||||
|
@ -109,6 +126,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
{:enabled, local_only || Config.get([:instance, :federated_timeline_available], true)},
|
{:enabled, local_only || Config.get([:instance, :federated_timeline_available], true)},
|
||||||
{:authenticated, true} <-
|
{:authenticated, true} <-
|
||||||
{:authenticated, !(is_nil(user) and restrict_unauthenticated?(timeline_type))} do
|
{:authenticated, !(is_nil(user) and restrict_unauthenticated?(timeline_type))} do
|
||||||
|
Logger.debug("TimelineController.public: fetching activities")
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
params
|
params
|
||||||
|> Map.put(:type, ["Create"])
|
|> Map.put(:type, ["Create"])
|
||||||
|
@ -121,6 +140,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|> Map.put(:includes_local_public, not is_nil(user))
|
|> Map.put(:includes_local_public, not is_nil(user))
|
||||||
|> ActivityPub.fetch_public_activities()
|
|> ActivityPub.fetch_public_activities()
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.public: rendering")
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(activities, %{"local" => local_only})
|
|> add_link_headers(activities, %{"local" => local_only})
|
||||||
|> render("index.json",
|
|> render("index.json",
|
||||||
|
@ -142,6 +163,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|
|
||||||
# GET /api/v1/timelines/bubble
|
# GET /api/v1/timelines/bubble
|
||||||
def bubble(%{assigns: %{user: user}} = conn, params) do
|
def bubble(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
Logger.debug("TimelineController.bubble")
|
||||||
|
|
||||||
if is_nil(user) and restrict_unauthenticated?(:bubble) do
|
if is_nil(user) and restrict_unauthenticated?(:bubble) do
|
||||||
fail_on_bad_auth(conn)
|
fail_on_bad_auth(conn)
|
||||||
else
|
else
|
||||||
|
@ -151,6 +174,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
[Pleroma.Web.Endpoint.host()]
|
[Pleroma.Web.Endpoint.host()]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.bubble: fetching activities")
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
params
|
params
|
||||||
|> Map.put(:type, ["Create"])
|
|> Map.put(:type, ["Create"])
|
||||||
|
@ -160,6 +185,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
|
||||||
|> Map.put(:instance, bubble_instances)
|
|> Map.put(:instance, bubble_instances)
|
||||||
|> ActivityPub.fetch_public_activities()
|
|> ActivityPub.fetch_public_activities()
|
||||||
|
|
||||||
|
Logger.debug("TimelineController.bubble: rendering")
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(activities)
|
|> add_link_headers(activities)
|
||||||
|> render("index.json",
|
|> render("index.json",
|
||||||
|
|
|
@ -21,6 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
alias Pleroma.Web.MediaProxy
|
alias Pleroma.Web.MediaProxy
|
||||||
alias Pleroma.Web.PleromaAPI.EmojiReactionController
|
alias Pleroma.Web.PleromaAPI.EmojiReactionController
|
||||||
|
require Logger
|
||||||
|
|
||||||
import Pleroma.Web.ActivityPub.Visibility, only: [get_visibility: 1, visible_for_user?: 2]
|
import Pleroma.Web.ActivityPub.Visibility, only: [get_visibility: 1, visible_for_user?: 2]
|
||||||
|
|
||||||
|
@ -87,6 +88,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
defp reblogged?(_activity, _user), do: false
|
defp reblogged?(_activity, _user), do: false
|
||||||
|
|
||||||
def render("index.json", opts) do
|
def render("index.json", opts) do
|
||||||
|
Logger.debug("Rendering index")
|
||||||
reading_user = opts[:for]
|
reading_user = opts[:for]
|
||||||
# To do: check AdminAPIControllerTest on the reasons behind nil activities in the list
|
# To do: check AdminAPIControllerTest on the reasons behind nil activities in the list
|
||||||
activities = Enum.filter(opts.activities, & &1)
|
activities = Enum.filter(opts.activities, & &1)
|
||||||
|
@ -136,8 +138,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
|
|
||||||
def render(
|
def render(
|
||||||
"show.json",
|
"show.json",
|
||||||
%{activity: %{data: %{"type" => "Announce", "object" => _object}} = activity} = opts
|
%{activity: %{id: id, data: %{"type" => "Announce", "object" => _object}} = activity} =
|
||||||
|
opts
|
||||||
) do
|
) do
|
||||||
|
Logger.debug("Rendering reblog #{id}")
|
||||||
user = CommonAPI.get_user(activity.data["actor"])
|
user = CommonAPI.get_user(activity.data["actor"])
|
||||||
created_at = Utils.to_masto_date(activity.data["published"])
|
created_at = Utils.to_masto_date(activity.data["published"])
|
||||||
object = Object.normalize(activity, fetch: false)
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
@ -209,7 +213,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
def render("show.json", %{activity: %{id: id, data: %{"object" => _object}} = activity} = opts) do
|
||||||
|
Logger.debug("Rendering status #{id}")
|
||||||
|
|
||||||
with %Object{} = object <- Object.normalize(activity, fetch: false) do
|
with %Object{} = object <- Object.normalize(activity, fetch: false) do
|
||||||
user = CommonAPI.get_user(activity.data["actor"])
|
user = CommonAPI.get_user(activity.data["actor"])
|
||||||
user_follower_address = user.follower_address
|
user_follower_address = user.follower_address
|
||||||
|
@ -428,6 +434,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("history.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
def render("history.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
||||||
|
Logger.debug("Rendering history for #{activity.id}")
|
||||||
object = Object.normalize(activity, fetch: false)
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
|
||||||
hashtags = Object.hashtags(object)
|
hashtags = Object.hashtags(object)
|
||||||
|
@ -614,6 +621,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
def render("attachment_meta.json", _), do: nil
|
def render("attachment_meta.json", _), do: nil
|
||||||
|
|
||||||
def render("context.json", %{activity: activity, activities: activities, user: user}) do
|
def render("context.json", %{activity: activity, activities: activities, user: user}) do
|
||||||
|
Logger.debug("Rendering context for #{activity.id}")
|
||||||
|
|
||||||
%{ancestors: ancestors, descendants: descendants} =
|
%{ancestors: ancestors, descendants: descendants} =
|
||||||
activities
|
activities
|
||||||
|> Enum.reverse()
|
|> Enum.reverse()
|
||||||
|
|
Loading…
Reference in a new issue