Merge branch 'account-notes' into 'develop'
[akkoma] / benchmarks / mix / tasks / pleroma / benchmarks / timelines.ex
1 defmodule Mix.Tasks.Pleroma.Benchmarks.Timelines do
2 use Mix.Task
3
4 import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
5
6 alias Pleroma.Web.CommonAPI
7 alias Plug.Conn
8
9 def run(_args) do
10 Mix.Pleroma.start_pleroma()
11
12 # Cleaning tables
13 clean_tables()
14
15 [{:ok, user} | users] = Pleroma.LoadTesting.Users.generate_users(1000)
16
17 # Let the user make 100 posts
18
19 1..100
20 |> Enum.each(fn i -> CommonAPI.post(user, %{status: to_string(i)}) end)
21
22 # Let 10 random users post
23 posts =
24 users
25 |> Enum.take_random(10)
26 |> Enum.map(fn {:ok, random_user} ->
27 {:ok, activity} = CommonAPI.post(random_user, %{status: "."})
28 activity
29 end)
30
31 # let our user repeat them
32 posts
33 |> Enum.each(fn activity ->
34 CommonAPI.repeat(activity.id, user)
35 end)
36
37 Benchee.run(
38 %{
39 "user timeline, no followers" => fn reading_user ->
40 conn =
41 Phoenix.ConnTest.build_conn()
42 |> Conn.assign(:user, reading_user)
43 |> Conn.assign(:skip_link_headers, true)
44
45 Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{id: user.id})
46 end
47 },
48 inputs: %{"user" => user, "no user" => nil},
49 time: 60
50 )
51
52 users
53 |> Enum.each(fn {:ok, follower} -> Pleroma.User.follow(follower, user) end)
54
55 Benchee.run(
56 %{
57 "user timeline, all following" => fn reading_user ->
58 conn =
59 Phoenix.ConnTest.build_conn()
60 |> Conn.assign(:user, reading_user)
61 |> Conn.assign(:skip_link_headers, true)
62
63 Pleroma.Web.MastodonAPI.AccountController.statuses(conn, %{id: user.id})
64 end
65 },
66 inputs: %{"user" => user, "no user" => nil},
67 time: 60
68 )
69 end
70 end