Ensured no auxiliary computations (actors list preparation etc.) related to relations...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 26 Mar 2020 18:54:01 +0000 (21:54 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 26 Mar 2020 18:54:01 +0000 (21:54 +0300)
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/mastodon_api/views/notification_view.ex
lib/pleroma/web/mastodon_api/views/status_view.ex

index 2cdfac7afbd2bf9d6fd4779f80d1fc9b5ade4ac1..0efcabc019b420f56c7b3a0e7f7c9f844b1ea07f 100644 (file)
@@ -14,10 +14,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
   def render("index.json", %{users: users} = opts) do
     relationships_opt =
-      if Map.has_key?(opts, :relationships) do
-        opts[:relationships]
-      else
-        UserRelationship.view_relationships_option(opts[:for], users)
+      cond do
+        Map.has_key?(opts, :relationships) ->
+          opts[:relationships]
+
+        is_nil(opts[:for]) ->
+          UserRelationship.view_relationships_option(nil, [])
+
+        true ->
+          UserRelationship.view_relationships_option(opts[:for], users)
       end
 
     opts = Map.put(opts, :relationships, relationships_opt)
@@ -134,10 +139,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
   def render("relationships.json", %{user: user, targets: targets} = opts) do
     relationships_opt =
-      if Map.has_key?(opts, :relationships) do
-        opts[:relationships]
-      else
-        UserRelationship.view_relationships_option(user, targets)
+      cond do
+        Map.has_key?(opts, :relationships) ->
+          opts[:relationships]
+
+        is_nil(opts[:for]) ->
+          UserRelationship.view_relationships_option(nil, [])
+
+        true ->
+          UserRelationship.view_relationships_option(user, targets)
       end
 
     render_opts = %{as: :target, user: user, relationships: relationships_opt}
index db434271c461e657cad4407e8011e9c677c036e7..a809080fd17f8f74c8d97f8ed65393becef55154 100644 (file)
@@ -32,21 +32,26 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
       |> Pleroma.Repo.all()
 
     relationships_opt =
-      if Map.has_key?(opts, :relationships) do
-        opts[:relationships]
-      else
-        move_activities_targets =
-          activities
-          |> Enum.filter(&(Activity.mastodon_notification_type(&1) == "move"))
-          |> Enum.map(&User.get_cached_by_ap_id(&1.data["target"]))
-
-        actors =
-          activities
-          |> Enum.map(fn a -> User.get_cached_by_ap_id(a.data["actor"]) end)
-          |> Enum.filter(& &1)
-          |> Kernel.++(move_activities_targets)
-
-        UserRelationship.view_relationships_option(reading_user, actors)
+      cond do
+        Map.has_key?(opts, :relationships) ->
+          opts[:relationships]
+
+        is_nil(opts[:for]) ->
+          UserRelationship.view_relationships_option(nil, [])
+
+        true ->
+          move_activities_targets =
+            activities
+            |> Enum.filter(&(Activity.mastodon_notification_type(&1) == "move"))
+            |> Enum.map(&User.get_cached_by_ap_id(&1.data["target"]))
+
+          actors =
+            activities
+            |> Enum.map(fn a -> User.get_cached_by_ap_id(a.data["actor"]) end)
+            |> Enum.filter(& &1)
+            |> Kernel.++(move_activities_targets)
+
+          UserRelationship.view_relationships_option(reading_user, actors)
       end
 
     opts = %{
index 7b1cb7bf8abd6c3ee7b89ca664f6b90bef91b379..d36b9ee5c49b456711cd0467e95e085806b9c48b 100644 (file)
@@ -87,11 +87,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       |> Repo.all()
 
     relationships_opt =
-      if Map.has_key?(opts, :relationships) do
-        opts[:relationships]
-      else
-        actors = Enum.map(activities ++ parent_activities, &get_user(&1.data["actor"]))
-        UserRelationship.view_relationships_option(opts[:for], actors)
+      cond do
+        Map.has_key?(opts, :relationships) ->
+          opts[:relationships]
+
+        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
 
     opts =