1 defmodule Pleroma.LoadTesting.Fetcher do
2 use Pleroma.LoadTesting.Helper
4 def fetch_user(user) do
6 "By id" => fn -> Repo.get_by(User, id: user.id) end,
7 "By ap_id" => fn -> Repo.get_by(User, ap_id: user.ap_id) end,
8 "By email" => fn -> Repo.get_by(User, email: user.email) end,
9 "By nickname" => fn -> Repo.get_by(User, nickname: user.nickname) end
13 def query_timelines(user) do
14 home_timeline_params = %{
17 "type" => ["Create", "Announce"],
18 "blocking_user" => user,
19 "muting_user" => user,
23 mastodon_public_timeline_params = %{
26 "only_media" => "false",
27 "type" => ["Create", "Announce"],
28 "with_muted" => "true",
29 "blocking_user" => user,
33 mastodon_federated_timeline_params = %{
35 "only_media" => "false",
36 "type" => ["Create", "Announce"],
37 "with_muted" => "true",
38 "blocking_user" => user,
43 "User home timeline" => fn ->
44 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
45 [user.ap_id | user.following],
49 "User mastodon public timeline" => fn ->
50 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
51 mastodon_public_timeline_params
54 "User mastodon federated public timeline" => fn ->
55 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
56 mastodon_federated_timeline_params
62 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
63 [user.ap_id | user.following],
68 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(mastodon_public_timeline_params)
70 public_federated_activities =
71 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
72 mastodon_federated_timeline_params
76 "Rendering home timeline" => fn ->
77 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
78 activities: home_activities,
83 "Rendering public timeline" => fn ->
84 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
85 activities: public_activities,
90 "Rendering public federated timeline" => fn ->
91 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
92 activities: public_federated_activities,
100 def query_notifications(user) do
101 without_muted_params = %{"count" => "20", "with_muted" => "false"}
102 with_muted_params = %{"count" => "20", "with_muted" => "true"}
105 "Notifications without muted" => fn ->
106 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
108 "Notifications with muted" => fn ->
109 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
113 without_muted_notifications =
114 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
116 with_muted_notifications =
117 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
120 "Render notifications without muted" => fn ->
121 Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
122 notifications: without_muted_notifications,
126 "Render notifications with muted" => fn ->
127 Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
128 notifications: with_muted_notifications,
135 def query_dms(user) do
138 "with_muted" => "true",
140 "blocking_user" => user,
146 "Direct messages with muted" => fn ->
147 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
148 |> Pleroma.Pagination.fetch_paginated(params)
150 "Direct messages without muted" => fn ->
151 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
152 |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
157 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
158 |> Pleroma.Pagination.fetch_paginated(params)
161 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
162 |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
165 "Rendering dms with muted" => fn ->
166 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
167 activities: dms_with_muted,
172 "Rendering dms without muted" => fn ->
173 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
174 activities: dms_without_muted,
182 def query_long_thread(user, activity) do
184 "Fetch main post" => fn ->
185 Pleroma.Activity.get_by_id_with_object(activity.id)
187 "Fetch context of main post" => fn ->
188 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
189 activity.data["context"],
191 "blocking_user" => user,
193 "exclude_id" => activity.id
199 activity = Pleroma.Activity.get_by_id_with_object(activity.id)
202 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
203 activity.data["context"],
205 "blocking_user" => user,
207 "exclude_id" => activity.id
212 "Render status" => fn ->
213 Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{
218 "Render context" => fn ->
219 Pleroma.Web.MastodonAPI.StatusView.render(