1 defmodule Mix.Tasks.Pleroma.Benchmarks.Tags do
4 import Pleroma.LoadTesting.Helper, only: [clean_tables: 0]
8 alias Pleroma.Web.MastodonAPI.TimelineController
11 Mix.Pleroma.start_pleroma()
12 activities_count = Repo.aggregate(from(a in Pleroma.Activity), :count, :id)
14 if activities_count == 0 do
15 IO.puts("Did not find any activities, cleaning and generating")
17 Pleroma.LoadTesting.Users.generate_users(10)
18 Pleroma.LoadTesting.Activities.generate_tagged_activities()
20 IO.puts("Found #{activities_count} activities, won't generate new ones")
23 tags = Enum.map(0..20, fn i -> {"For #tag_#{i}", "tag_#{i}"} end)
25 Enum.each(tags, fn {_, tag} ->
27 from(o in Pleroma.Object,
28 where: fragment("(?)->'tag' \\? (?)", o.data, ^tag)
31 count = Repo.aggregate(query, :count, :id)
32 IO.puts("Database contains #{count} posts tagged with #{tag}")
35 user = Repo.all(Pleroma.User) |> List.first()
39 "Hashtag fetching, any" => fn tags ->
40 TimelineController.hashtag_fetching(
48 # Will always return zero results because no overlapping hashtags are generated.
49 "Hashtag fetching, all" => fn tags ->
50 TimelineController.hashtag_fetching(
61 |> Enum.map(fn {_, v} -> v end)
62 |> Enum.chunk_every(2)
63 |> Enum.map(fn tags -> {"For #{inspect(tags)}", tags} end),
69 "Hashtag fetching" => fn tag ->
70 TimelineController.hashtag_fetching(