Add a task to benchmark timeline rendering
authorrinpatch <rinpatch@sdf.org>
Wed, 14 Aug 2019 21:43:02 +0000 (00:43 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 14 Aug 2019 21:43:02 +0000 (00:43 +0300)
lib/mix/tasks/pleroma/benchmark.ex

index 5222cce8022f97f328c678a8a4f2350f733b1cc2..a45940bf3edfae6cb114617efff2e0cb384e0405 100644 (file)
@@ -26,4 +26,28 @@ defmodule Mix.Tasks.Pleroma.Benchmark do
       end
     })
   end
+
+  def run(["render_timeline", nickname]) do
+    start_pleroma()
+    user = Pleroma.User.get_by_nickname(nickname)
+
+    activities =
+      %{}
+      |> Map.put("type", ["Create", "Announce"])
+      |> Map.put("blocking_user", user)
+      |> Map.put("muting_user", user)
+      |> Map.put("user", user)
+      |> Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities()
+      |> Enum.reverse()
+
+    Benchee.run(%{
+      "render_timeline" => fn ->
+        Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
+          activities: activities,
+          for: user,
+          as: :activity
+        })
+      end
+    })
+  end
 end