Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
6.6KB

  1. defmodule Pleroma.LoadTesting.Fetcher do
  2. use Pleroma.LoadTesting.Helper
  3. def fetch_user(user) do
  4. Benchee.run(%{
  5. "By id" => fn -> Repo.get_by(User, id: user.id) end,
  6. "By ap_id" => fn -> Repo.get_by(User, ap_id: user.ap_id) end,
  7. "By email" => fn -> Repo.get_by(User, email: user.email) end,
  8. "By nickname" => fn -> Repo.get_by(User, nickname: user.nickname) end
  9. })
  10. end
  11. def query_timelines(user) do
  12. home_timeline_params = %{
  13. "count" => 20,
  14. "with_muted" => true,
  15. "type" => ["Create", "Announce"],
  16. "blocking_user" => user,
  17. "muting_user" => user,
  18. "user" => user
  19. }
  20. mastodon_public_timeline_params = %{
  21. "count" => 20,
  22. "local_only" => true,
  23. "only_media" => "false",
  24. "type" => ["Create", "Announce"],
  25. "with_muted" => "true",
  26. "blocking_user" => user,
  27. "muting_user" => user
  28. }
  29. mastodon_federated_timeline_params = %{
  30. "count" => 20,
  31. "only_media" => "false",
  32. "type" => ["Create", "Announce"],
  33. "with_muted" => "true",
  34. "blocking_user" => user,
  35. "muting_user" => user
  36. }
  37. Benchee.run(%{
  38. "User home timeline" => fn ->
  39. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
  40. [user.ap_id | user.following],
  41. home_timeline_params
  42. )
  43. end,
  44. "User mastodon public timeline" => fn ->
  45. Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
  46. mastodon_public_timeline_params
  47. )
  48. end,
  49. "User mastodon federated public timeline" => fn ->
  50. Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
  51. mastodon_federated_timeline_params
  52. )
  53. end
  54. })
  55. home_activities =
  56. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
  57. [user.ap_id | user.following],
  58. home_timeline_params
  59. )
  60. public_activities =
  61. Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(mastodon_public_timeline_params)
  62. public_federated_activities =
  63. Pleroma.Web.ActivityPub.ActivityPub.fetch_public_activities(
  64. mastodon_federated_timeline_params
  65. )
  66. Benchee.run(%{
  67. "Rendering home timeline" => fn ->
  68. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  69. activities: home_activities,
  70. for: user,
  71. as: :activity
  72. })
  73. end,
  74. "Rendering public timeline" => fn ->
  75. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  76. activities: public_activities,
  77. for: user,
  78. as: :activity
  79. })
  80. end,
  81. "Rendering public federated timeline" => fn ->
  82. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  83. activities: public_federated_activities,
  84. for: user,
  85. as: :activity
  86. })
  87. end
  88. })
  89. end
  90. def query_notifications(user) do
  91. without_muted_params = %{"count" => "20", "with_muted" => "false"}
  92. with_muted_params = %{"count" => "20", "with_muted" => "true"}
  93. Benchee.run(%{
  94. "Notifications without muted" => fn ->
  95. Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
  96. end,
  97. "Notifications with muted" => fn ->
  98. Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
  99. end
  100. })
  101. without_muted_notifications =
  102. Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
  103. with_muted_notifications =
  104. Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
  105. Benchee.run(%{
  106. "Render notifications without muted" => fn ->
  107. Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
  108. notifications: without_muted_notifications,
  109. for: user
  110. })
  111. end,
  112. "Render notifications with muted" => fn ->
  113. Pleroma.Web.MastodonAPI.NotificationView.render("index.json", %{
  114. notifications: with_muted_notifications,
  115. for: user
  116. })
  117. end
  118. })
  119. end
  120. def query_dms(user) do
  121. params = %{
  122. "count" => "20",
  123. "with_muted" => "true",
  124. "type" => "Create",
  125. "blocking_user" => user,
  126. "user" => user,
  127. visibility: "direct"
  128. }
  129. Benchee.run(%{
  130. "Direct messages with muted" => fn ->
  131. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
  132. |> Pleroma.Pagination.fetch_paginated(params)
  133. end,
  134. "Direct messages without muted" => fn ->
  135. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
  136. |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
  137. end
  138. })
  139. dms_with_muted =
  140. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
  141. |> Pleroma.Pagination.fetch_paginated(params)
  142. dms_without_muted =
  143. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
  144. |> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
  145. Benchee.run(%{
  146. "Rendering dms with muted" => fn ->
  147. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  148. activities: dms_with_muted,
  149. for: user,
  150. as: :activity
  151. })
  152. end,
  153. "Rendering dms without muted" => fn ->
  154. Pleroma.Web.MastodonAPI.StatusView.render("index.json", %{
  155. activities: dms_without_muted,
  156. for: user,
  157. as: :activity
  158. })
  159. end
  160. })
  161. end
  162. def query_long_thread(user, activity) do
  163. Benchee.run(%{
  164. "Fetch main post" => fn ->
  165. Pleroma.Activity.get_by_id_with_object(activity.id)
  166. end,
  167. "Fetch context of main post" => fn ->
  168. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
  169. activity.data["context"],
  170. %{
  171. "blocking_user" => user,
  172. "user" => user,
  173. "exclude_id" => activity.id
  174. }
  175. )
  176. end
  177. })
  178. activity = Pleroma.Activity.get_by_id_with_object(activity.id)
  179. context =
  180. Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
  181. activity.data["context"],
  182. %{
  183. "blocking_user" => user,
  184. "user" => user,
  185. "exclude_id" => activity.id
  186. }
  187. )
  188. Benchee.run(%{
  189. "Render status" => fn ->
  190. Pleroma.Web.MastodonAPI.StatusView.render("show.json", %{
  191. activity: activity,
  192. for: user
  193. })
  194. end,
  195. "Render context" => fn ->
  196. Pleroma.Web.MastodonAPI.StatusView.render(
  197. "index.json",
  198. for: user,
  199. activities: context,
  200. as: :activity
  201. )
  202. |> Enum.reverse()
  203. end
  204. })
  205. end
  206. end