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,
42 following = User.following(user)
45 "User home timeline" => fn ->
46 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
51 "User mastodon public timeline" => fn ->
52 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
53 mastodon_public_timeline_params
56 "User mastodon federated public timeline" => fn ->
57 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
58 mastodon_federated_timeline_params
61 "User favourites timeline" => fn ->
62 Pleroma.Web.ActivityPub.ActivityPub.fetch_favourites(user)
67 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
73 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(mastodon_public_timeline_params)
75 public_federated_activities =
76 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
77 mastodon_federated_timeline_params
80 user_favourites = Pleroma.Web.ActivityPub.ActivityPub.fetch_favourites(user)
83 "Rendering home timeline" => fn ->
84 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
85 activities: home_activities,
90 "Rendering public timeline" => fn ->
91 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
92 activities: public_activities,
97 "Rendering public federated timeline" => fn ->
98 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
99 activities: public_federated_activities,
104 "Rendering favorites timeline" => fn ->
105 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
106 activities: user_favourites,
113 def query_notifications(user) do
114 without_muted_params = %{"count" => "20", "with_muted" => "false"}
115 with_muted_params = %{"count" => "20", "with_muted" => "true"}
118 "Notifications without muted" => fn ->
119 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
121 "Notifications with muted" => fn ->
122 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
126 without_muted_notifications =
127 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
129 with_muted_notifications =
130 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
133 "Render notifications without muted" => fn ->
134 Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
135 notifications: without_muted_notifications,
139 "Render notifications with muted" => fn ->
140 Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
141 notifications: with_muted_notifications,
148 def query_dms(user) do
151 "with_muted" => "true",
153 "blocking_user" => user,
159 "Direct messages with muted" => fn ->
160 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
161 |> Pleroma.Pagination.fetch_paginated(params)
163 "Direct messages without muted" => fn ->
164 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
165 |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
170 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
171 |> Pleroma.Pagination.fetch_paginated(params)
174 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
175 |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
178 "Rendering dms with muted" => fn ->
179 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
180 activities: dms_with_muted,
185 "Rendering dms without muted" => fn ->
186 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
187 activities: dms_without_muted,
195 def query_long_thread(user, activity) do
197 "Fetch main post" => fn ->
198 Pleroma.Activity.get_by_id_with_object(activity.id)
200 "Fetch context of main post" => fn ->
201 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
202 activity.data["context"],
204 "blocking_user" => user,
206 "exclude_id" => activity.id
212 activity = Pleroma.Activity.get_by_id_with_object(activity.id)
215 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
216 activity.data["context"],
218 "blocking_user" => user,
220 "exclude_id" => activity.id
225 "Render status" => fn ->
226 Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{
231 "Render context" => fn ->
232 Pleroma.Web.MastodonAPI.StatusView.render(