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
64 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
70 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(mastodon_public_timeline_params)
72 public_federated_activities =
73 Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
74 mastodon_federated_timeline_params
78 "Rendering home timeline" => fn ->
79 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
80 activities: home_activities,
85 "Rendering public timeline" => fn ->
86 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
87 activities: public_activities,
92 "Rendering public federated timeline" => fn ->
93 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
94 activities: public_federated_activities,
99 "Rendering favorites timeline" => fn ->
100 conn = Phoenix.ConnTest.build_conn(:get, "http://localhost:4001/api/v1/favourites", nil)
101 Pleroma.Web.MastodonAPI.StatusController.favourites(
103 assigns: %{user: user},
104 query_params: %{"limit" => "0"},
110 Pleroma.Web.Router => {[], %{}},
111 phoenix_router: Pleroma.Web.Router,
112 phoenix_action: :favourites,
113 phoenix_controller: Pleroma.Web.MastodonAPI.StatusController,
114 phoenix_endpoint: Pleroma.Web.Endpoint,
115 phoenix_format: "json",
116 phoenix_layout: {Pleroma.Web.LayoutView, "app.html"},
117 phoenix_recycled: true,
119 phoenix_view: Pleroma.Web.MastodonAPI.StatusView,
120 plug_session: %{"user_id" => user.id},
121 plug_session_fetch: :done,
122 plug_session_info: :write,
123 plug_skip_csrf_protection: true
131 def query_notifications(user) do
132 without_muted_params = %{"count" => "20", "with_muted" => "false"}
133 with_muted_params = %{"count" => "20", "with_muted" => "true"}
136 "Notifications without muted" => fn ->
137 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
139 "Notifications with muted" => fn ->
140 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
144 without_muted_notifications =
145 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
147 with_muted_notifications =
148 Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
151 "Render notifications without muted" => fn ->
152 Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
153 notifications: without_muted_notifications,
157 "Render notifications with muted" => fn ->
158 Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
159 notifications: with_muted_notifications,
166 def query_dms(user) do
169 "with_muted" => "true",
171 "blocking_user" => user,
177 "Direct messages with muted" => fn ->
178 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
179 |> Pleroma.Pagination.fetch_paginated(params)
181 "Direct messages without muted" => fn ->
182 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
183 |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
188 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
189 |> Pleroma.Pagination.fetch_paginated(params)
192 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
193 |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
196 "Rendering dms with muted" => fn ->
197 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
198 activities: dms_with_muted,
203 "Rendering dms without muted" => fn ->
204 Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
205 activities: dms_without_muted,
213 def query_long_thread(user, activity) do
215 "Fetch main post" => fn ->
216 Pleroma.Activity.get_by_id_with_object(activity.id)
218 "Fetch context of main post" => fn ->
219 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
220 activity.data["context"],
222 "blocking_user" => user,
224 "exclude_id" => activity.id
230 activity = Pleroma.Activity.get_by_id_with_object(activity.id)
233 Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
234 activity.data["context"],
236 "blocking_user" => user,
238 "exclude_id" => activity.id
243 "Render status" => fn ->
244 Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{
249 "Render context" => fn ->
250 Pleroma.Web.MastodonAPI.StatusView.render(