temp commit
[akkoma] / lib / load_testing / fetcher.ex
1 defmodule Pleroma.LoadTesting.Fetcher do
2 use Pleroma.LoadTesting.Helper
3
4 def fetch_user(user) do
5 IO.puts("=================================")
6
7 {time, _value} = :timer.tc(fn -> Repo.get_by(User, id: user.id) end)
8
9 IO.puts("Query user by id: #{to_sec(time)} sec.")
10
11 {time, _value} =
12 :timer.tc(fn ->
13 Repo.get_by(User, ap_id: user.ap_id)
14 end)
15
16 IO.puts("Query user by ap_id: #{to_sec(time)} sec.")
17
18 {time, _value} =
19 :timer.tc(fn ->
20 Repo.get_by(User, email: user.email)
21 end)
22
23 IO.puts("Query user by email: #{to_sec(time)} sec.")
24
25 {time, _value} = :timer.tc(fn -> Repo.get_by(User, nickname: user.nickname) end)
26
27 IO.puts("Query user by nickname: #{to_sec(time)} sec.")
28 end
29
30 def query_timelines(user) do
31 IO.puts("\n=================================")
32
33 params = %{
34 "count" => 20,
35 "with_muted" => true,
36 "type" => ["Create", "Announce"],
37 "blocking_user" => user,
38 "muting_user" => user,
39 "user" => user
40 }
41
42 {time, _} =
43 :timer.tc(fn ->
44 ActivityPub.ActivityPub.fetch_activities([user.ap_id | user.following], params)
45 end)
46
47 IO.puts("Query user home timeline: #{to_sec(time)} sec.")
48
49 params = %{
50 "count" => 20,
51 "local_only" => true,
52 "only_media" => "false",
53 "type" => ["Create", "Announce"],
54 "with_muted" => "true",
55 "blocking_user" => user,
56 "muting_user" => user
57 }
58
59 {time, _} =
60 :timer.tc(fn ->
61 ActivityPub.ActivityPub.fetch_public_activities(params)
62 end)
63
64 IO.puts("Query user mastodon public timeline: #{to_sec(time)} sec.")
65
66 params = %{
67 "count" => 20,
68 "only_media" => "false",
69 "type" => ["Create", "Announce"],
70 "with_muted" => "true",
71 "blocking_user" => user,
72 "muting_user" => user
73 }
74
75 {time, _} =
76 :timer.tc(fn ->
77 ActivityPub.ActivityPub.fetch_public_activities(params)
78 end)
79
80 IO.puts("Query user mastodon federated public timeline: #{to_sec(time)} sec.")
81 end
82
83 def query_notifications(user) do
84 IO.puts("\n=================================")
85 params = %{"count" => "20", "with_muted" => "false"}
86
87 {time, _} =
88 :timer.tc(fn -> Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, params) end)
89
90 IO.puts("Query user notifications with out muted: #{to_sec(time)} sec.")
91
92 params = %{"count" => "20", "with_muted" => "true"}
93
94 {time, _} =
95 :timer.tc(fn -> Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, params) end)
96
97 IO.puts("Query user notifications with muted: #{to_sec(time)} sec.")
98 end
99
100 def query_long_thread(user, activity) do
101 IO.puts("\n=================================")
102
103 {time, replies} =
104 :timer.tc(fn ->
105 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
106 activity.data["context"],
107 %{
108 "blocking_user" => user,
109 "user" => user
110 }
111 )
112 end)
113
114 IO.puts("Query long thread with #{length(replies)} replies: #{to_sec(time)} sec.")
115 end
116 end