1 defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
4 alias Pleroma.LoadTesting.Generator
6 alias Pleroma.Web.CommonAPI
9 Mix.Pleroma.start_pleroma()
14 [{:ok, user} | users] = Generator.generate_users(users_max: 1000)
16 # Let the user make 100 posts
19 |> Enum.each(fn i -> CommonAPI.post(user, %{"status" => to_string(i)}) end)
21 # Let 10 random users post
24 |> Enum.take_random(10)
25 |> Enum.map(fn {:ok, random_user} ->
26 {:ok, activity} = CommonAPI.post(random_user, %{"status" => "."})
30 # let our user repeat them
32 |> Enum.each(fn activity ->
33 CommonAPI.repeat(activity.id, user)
38 "user timeline, no followers" => fn reading_user ->
40 Phoenix.ConnTest.build_conn()
41 |> Plug.Conn.assign(:user, reading_user)
42 |> Plug.Conn.assign(:skip_link_headers, true)
44 Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id})
47 inputs: %{"user" => user, "no user" => nil},
52 |> Enum.each(fn {:ok, follower} -> Pleroma.User.follow(follower, user) end)
56 "user timeline, all following" => fn reading_user ->
58 Phoenix.ConnTest.build_conn()
59 |> Plug.Conn.assign(:user, reading_user)
60 |> Plug.Conn.assign(:skip_link_headers, true)
62 Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{"id" => user.id})
65 inputs: %{"user" => user, "no user" => nil},
71 IO.puts("Deleting old data...\n")
72 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE users CASCADE;")
73 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE activities CASCADE;")
74 Ecto.Adapters.SQL.query!(Repo, "TRUNCATE objects CASCADE;")