1 defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
4 import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
6 alias Pleroma.Web.CommonAPI
10 Mix.Pleroma.start_pleroma()
15 [{:ok, user} | users] = Pleroma.LoadTesting.Users.generate_users(1000)
17 # Let the user make 100 posts
20 |> Enum.each(fn i -> CommonAPI.post(user, %{status: to_string(i)}) end)
22 # Let 10 random users post
25 |> Enum.take_random(10)
26 |> Enum.map(fn {:ok, random_user} ->
27 {:ok, activity} = CommonAPI.post(random_user, %{status: "."})
31 # let our user repeat them
33 |> Enum.each(fn activity ->
34 CommonAPI.repeat(activity.id, user)
39 "user timeline, no followers" => fn reading_user ->
41 Phoenix.ConnTest.build_conn()
42 |> Conn.assign(:user, reading_user)
43 |> Conn.assign(:skip_link_headers, true)
45 Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{id: user.id})
48 inputs: %{"user" => user, "no user" => nil},
53 |> Enum.each(fn {:ok, follower} -> Pleroma.User.follow(follower, user) end)
57 "user timeline, all following" => fn reading_user ->
59 Phoenix.ConnTest.build_conn()
60 |> Conn.assign(:user, reading_user)
61 |> Conn.assign(:skip_link_headers, true)
63 Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{id: user.id})
66 inputs: %{"user" => user, "no user" => nil},