non_friends_used: 20
]
- @max_concurrency 30
+ @max_concurrency 10
@visibility ~w(public private direct unlisted)
@types ~w(simple emoji mentions hell_thread attachment tag like reblog simple_thread remote)
)
end)
- IO.puts("Generating iterations activities take #{to_sec(time)} sec.\n")
+ IO.puts("Generating iterations of activities took #{to_sec(time)} sec.\n")
:ok
end
+ def generate_power_intervals(opts \\ []) do
+ count = Keyword.get(opts, :count, 20)
+ power = Keyword.get(opts, :power, 2)
+ IO.puts("Generating #{count} intervals for a power #{power} series...")
+ counts = Enum.map(1..count, fn n -> :math.pow(n, power) end)
+ sum = Enum.sum(counts)
+
+ densities =
+ Enum.map(counts, fn c ->
+ c / sum
+ end)
+
+ densities
+ |> Enum.reduce(0, fn density, acc ->
+ if acc == 0 do
+ [{0, density}]
+ else
+ [{_, lower} | _] = acc
+ [{lower, lower + density} | acc]
+ end
+ end)
+ |> Enum.reverse()
+ end
+
+ def generate_tagged_activities(opts \\ []) do
+ tag_count = Keyword.get(opts, :tag_count, 20)
+ users = Keyword.get(opts, :users, Repo.all(Pleroma.User))
+ activity_count = Keyword.get(opts, :count, 200_000)
+
+ intervals = generate_power_intervals(count: tag_count)
+
+ IO.puts(
+ "Generating #{activity_count} activities using #{tag_count} different tags of format `tag_n`, starting at tag_0"
+ )
+
+ Enum.each(1..activity_count, fn _ ->
+ random = :rand.uniform()
+ i = Enum.find_index(intervals, fn {lower, upper} -> lower <= random && upper > random end)
+ CommonAPI.post(Enum.random(users), %{status: "a post with the tag #tag_#{i}"})
+ end)
+ end
+
defp generate_long_thread(visibility, user, friends, non_friends, _opts) do
group =
if visibility == "public",
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Start of #{visibility} long thread",
- "visibility" => visibility
+ status: "Start of #{visibility} long thread",
+ visibility: visibility
})
Agent.update(:benchmark_state, fn state ->
{:ok, _activity} =
group
|> get_actor(user, friends, non_friends)
- |> CommonAPI.post(%{"status" => "Simple status", "visibility" => visibility})
+ |> CommonAPI.post(%{status: "Simple status", visibility: visibility})
end
defp insert_activity("emoji", visibility, group, user, friends, non_friends, _opts) do
group
|> get_actor(user, friends, non_friends)
|> CommonAPI.post(%{
- "status" => "Simple status with emoji :firefox:",
- "visibility" => visibility
+ status: "Simple status with emoji :firefox:",
+ visibility: visibility
})
end
group
|> get_actor(user, friends, non_friends)
|> CommonAPI.post(%{
- "status" => Enum.join(user_mentions, ", ") <> " simple status with mentions",
- "visibility" => visibility
+ status: Enum.join(user_mentions, ", ") <> " simple status with mentions",
+ visibility: visibility
})
end
group
|> get_actor(user, friends, non_friends)
|> CommonAPI.post(%{
- "status" => mentions <> " hell thread status",
- "visibility" => visibility
+ status: mentions <> " hell thread status",
+ visibility: visibility
})
end
{:ok, _activity} =
CommonAPI.post(actor, %{
- "status" => "Post with attachment",
- "visibility" => visibility,
- "media_ids" => [object.id]
+ status: "Post with attachment",
+ visibility: visibility,
+ media_ids: [object.id]
})
end
{:ok, _activity} =
group
|> get_actor(user, friends, non_friends)
- |> CommonAPI.post(%{"status" => "Status with #tag", "visibility" => visibility})
+ |> CommonAPI.post(%{status: "Status with #tag", visibility: visibility})
end
defp insert_activity("like", visibility, group, user, friends, non_friends, opts) do
actor = get_actor(group, user, friends, non_friends)
with activity_id when not is_nil(activity_id) <- get_random_create_activity_id(),
- {:ok, _activity, _object} <- CommonAPI.favorite(activity_id, actor) do
+ {:ok, _activity} <- CommonAPI.favorite(actor, activity_id) do
:ok
else
{:error, _} ->
actor = get_actor(group, user, friends, non_friends)
tasks = get_reply_tasks(visibility, group)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "Simple status", "visibility" => "unlisted"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "Simple status", visibility: visibility})
acc = {activity.id, ["@" <> actor.nickname, "reply to status"]}
insert_replies(tasks, visibility, user, friends, non_friends, acc)
{:ok, activity} =
CommonAPI.post(actor, %{
- "status" => Enum.join(data, ", ") <> "simple status",
- "visibility" => "direct"
+ status: Enum.join(data, ", ") <> "simple status",
+ visibility: "direct"
})
acc = {activity.id, ["@" <> user.nickname | data] ++ ["reply to status"]}
defp insert_reply(actor, data, activity_id, visibility) do
{:ok, reply} =
CommonAPI.post(actor, %{
- "status" => Enum.join(data, ", "),
- "visibility" => visibility,
- "in_reply_to_status_id" => activity_id
+ status: Enum.join(data, ", "),
+ visibility: visibility,
+ in_reply_to_status_id: activity_id
})
{reply.id, ["@" <> actor.nickname | data]}