Ensured no auxiliary computations (actors list preparation etc.) related to relationships preloading if no user is present (for statuses / accounts / relationships rendering).

This commit is contained in:
Ivan Tashkinov 2020-03-26 21:54:01 +03:00
parent 112101ca52
commit 6b793d3f83
3 changed files with 47 additions and 26 deletions

View File

@ -14,9 +14,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
def render("index.json", %{users: users} = opts) do
relationships_opt =
if Map.has_key?(opts, :relationships) do
cond do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
else
is_nil(opts[:for]) ->
UserRelationship.view_relationships_option(nil, [])
true ->
UserRelationship.view_relationships_option(opts[:for], users)
end
@ -134,9 +139,14 @@ def render(
def render("relationships.json", %{user: user, targets: targets} = opts) do
relationships_opt =
if Map.has_key?(opts, :relationships) do
cond do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
else
is_nil(opts[:for]) ->
UserRelationship.view_relationships_option(nil, [])
true ->
UserRelationship.view_relationships_option(user, targets)
end

View File

@ -32,9 +32,14 @@ def render("index.json", %{notifications: notifications, for: reading_user} = op
|> Pleroma.Repo.all()
relationships_opt =
if Map.has_key?(opts, :relationships) do
cond do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
else
is_nil(opts[:for]) ->
UserRelationship.view_relationships_option(nil, [])
true ->
move_activities_targets =
activities
|> Enum.filter(&(Activity.mastodon_notification_type(&1) == "move"))

View File

@ -87,10 +87,16 @@ def render("index.json", opts) do
|> Repo.all()
relationships_opt =
if Map.has_key?(opts, :relationships) do
cond do
Map.has_key?(opts, :relationships) ->
opts[:relationships]
else
is_nil(opts[:for]) ->
UserRelationship.view_relationships_option(nil, [])
true ->
actors = Enum.map(activities ++ parent_activities, &get_user(&1.data["actor"]))
UserRelationship.view_relationships_option(opts[:for], actors)
end