2019-08-02 20:33:12 +02:00
|
|
|
defmodule Pleroma.LoadTesting.Fetcher do
|
|
|
|
use Pleroma.LoadTesting.Helper
|
|
|
|
|
|
|
|
def fetch_user(user) do
|
|
|
|
IO.puts("=================================")
|
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
Benchee.run(%{
|
|
|
|
"By id" => fn -> Repo.get_by(User, id: user.id) end,
|
|
|
|
"By ap_id" => fn -> Repo.get_by(User, ap_id: user.ap_id) end,
|
|
|
|
"By email" => fn -> Repo.get_by(User, email: user.email) end,
|
|
|
|
"By nickname" => fn -> Repo.get_by(User, nickname: user.nickname) end
|
|
|
|
})
|
2019-08-02 20:33:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def query_timelines(user) do
|
|
|
|
IO.puts("\n=================================")
|
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
home_timeline_params = %{
|
2019-08-02 20:33:12 +02:00
|
|
|
"count" => 20,
|
|
|
|
"with_muted" => true,
|
|
|
|
"type" => ["Create", "Announce"],
|
|
|
|
"blocking_user" => user,
|
|
|
|
"muting_user" => user,
|
|
|
|
"user" => user
|
|
|
|
}
|
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
mastodon_public_timeline_params = %{
|
2019-08-02 20:33:12 +02:00
|
|
|
"count" => 20,
|
|
|
|
"local_only" => true,
|
|
|
|
"only_media" => "false",
|
|
|
|
"type" => ["Create", "Announce"],
|
|
|
|
"with_muted" => "true",
|
|
|
|
"blocking_user" => user,
|
|
|
|
"muting_user" => user
|
|
|
|
}
|
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
mastodon_federated_timeline_params = %{
|
2019-08-02 20:33:12 +02:00
|
|
|
"count" => 20,
|
|
|
|
"only_media" => "false",
|
|
|
|
"type" => ["Create", "Announce"],
|
|
|
|
"with_muted" => "true",
|
|
|
|
"blocking_user" => user,
|
|
|
|
"muting_user" => user
|
|
|
|
}
|
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
Benchee.run(%{
|
|
|
|
"User home timeline" => fn ->
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities(
|
|
|
|
[user.ap_id | user.following],
|
|
|
|
home_timeline_params
|
|
|
|
)
|
|
|
|
end,
|
|
|
|
"User mastodon public timeline" => fn ->
|
|
|
|
ActivityPub.ActivityPub.fetch_public_activities(mastodon_public_timeline_params)
|
|
|
|
end,
|
|
|
|
"User mastodon federated public timeline" => fn ->
|
|
|
|
ActivityPub.ActivityPub.fetch_public_activities(mastodon_federated_timeline_params)
|
|
|
|
end
|
|
|
|
})
|
2019-08-02 20:33:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def query_notifications(user) do
|
|
|
|
IO.puts("\n=================================")
|
2019-09-04 19:18:11 +02:00
|
|
|
without_muted_params = %{"count" => "20", "with_muted" => "false"}
|
|
|
|
with_muted_params = %{"count" => "20", "with_muted" => "true"}
|
|
|
|
|
|
|
|
Benchee.run(%{
|
|
|
|
"Notifications without muted" => fn ->
|
|
|
|
Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, without_muted_params)
|
|
|
|
end,
|
|
|
|
"Notifications with muted" => fn ->
|
|
|
|
Pleroma.Web.MastodonAPI.MastodonAPI.get_notifications(user, with_muted_params)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2019-08-02 20:33:12 +02:00
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
def query_dms(user) do
|
|
|
|
IO.puts("\n=================================")
|
2019-08-02 20:33:12 +02:00
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
params = %{
|
|
|
|
"count" => "20",
|
|
|
|
"with_muted" => "true",
|
|
|
|
"type" => "Create",
|
|
|
|
"blocking_user" => user,
|
|
|
|
"user" => user,
|
|
|
|
visibility: "direct"
|
|
|
|
}
|
2019-08-02 20:33:12 +02:00
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
Benchee.run(%{
|
|
|
|
"Direct messages with muted" => fn ->
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
|
|
|
|
|> Pleroma.Pagination.fetch_paginated(params)
|
|
|
|
end,
|
|
|
|
"Direct messages without muted" => fn ->
|
|
|
|
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_query([user.ap_id], params)
|
|
|
|
|> Pleroma.Pagination.fetch_paginated(Map.put(params, "with_muted", false))
|
|
|
|
end
|
|
|
|
})
|
2019-08-02 20:33:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def query_long_thread(user, activity) do
|
|
|
|
IO.puts("\n=================================")
|
|
|
|
|
2019-09-04 19:18:11 +02:00
|
|
|
Benchee.run(%{
|
|
|
|
"Fetch main post" => fn -> Activity.get_by_id_with_object(activity.id) end,
|
|
|
|
"Fetch context of main post" => fn ->
|
2019-08-02 20:33:12 +02:00
|
|
|
Pleroma.Web.ActivityPub.ActivityPub.fetch_activities_for_context(
|
|
|
|
activity.data["context"],
|
|
|
|
%{
|
|
|
|
"blocking_user" => user,
|
2019-09-04 19:18:11 +02:00
|
|
|
"user" => user,
|
|
|
|
"exclude_id" => activity.id
|
2019-08-02 20:33:12 +02:00
|
|
|
}
|
|
|
|
)
|
2019-09-04 19:18:11 +02:00
|
|
|
end
|
|
|
|
})
|
2019-08-02 20:33:12 +02:00
|
|
|
end
|
|
|
|
end
|