1 defmodule Pleroma.LoadTesting.Fetcher do
2 use Pleroma.LoadTesting.Helper
4 def fetch_user(user) do
5 IO.puts("=================================")
7 {time, _value} = :timer.tc(fn -> Repo.get_by(User, id: user.id) end)
9 IO.puts("Query user by id: #{to_sec(time)} sec.")
13 Repo.get_by(User, ap_id: user.ap_id)
16 IO.puts("Query user by ap_id: #{to_sec(time)} sec.")
20 Repo.get_by(User, email: user.email)
23 IO.puts("Query user by email: #{to_sec(time)} sec.")
25 {time, _value} = :timer.tc(fn -> Repo.get_by(User, nickname: user.nickname) end)
27 IO.puts("Query user by nickname: #{to_sec(time)} sec.")
30 def query_timelines(user) do
31 IO.puts("\n=================================")
36 "type" => ["Create", "Announce"],
37 "blocking_user" => user,
38 "muting_user" => user,
44 ActivityPub.ActivityPub.fetch_activities([user.ap_id | user.following], params)
47 IO.puts("Query user home timeline: #{to_sec(time)} sec.")
52 "only_media" => "false",
53 "type" => ["Create", "Announce"],
54 "with_muted" => "true",
55 "blocking_user" => user,
61 ActivityPub.ActivityPub.fetch_public_activities(params)
64 IO.puts("Query user mastodon public timeline: #{to_sec(time)} sec.")
68 "only_media" => "false",
69 "type" => ["Create", "Announce"],
70 "with_muted" => "true",
71 "blocking_user" => user,
77 ActivityPub.ActivityPub.fetch_public_activities(params)
80 IO.puts("Query user mastodon federated public timeline: #{to_sec(time)} sec.")
83 def query_notifications(user) do
84 IO.puts("\n=================================")
85 params = %{"count" => "20", "with_muted" => "false"}
88 :timer.tc(fn -> Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, params) end)
90 IO.puts("Query user notifications with out muted: #{to_sec(time)} sec.")
92 params = %{"count" => "20", "with_muted" => "true"}
95 :timer.tc(fn -> Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, params) end)
97 IO.puts("Query user notifications with muted: #{to_sec(time)} sec.")
100 def query_long_thread(user, activity) do
101 IO.puts("\n=================================")
105 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
106 activity.data["context"],
108 "blocking_user" => user,
114 IO.puts("Query long thread with #{length(replies)} replies: #{to_sec(time)} sec.")