use aggregate for domain count

This commit is contained in:
Hannah Ward 2024-12-10 16:19:34 +00:00
parent 294de939cb
commit 1df8658d0d

View file

@ -10,6 +10,7 @@ defmodule Pleroma.Stats do
alias Pleroma.CounterCache
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Instance
@interval :timer.seconds(300)
@ -64,16 +65,11 @@ defmodule Pleroma.Stats do
}
}
def calculate_stat_data do
peers =
domain_count =
from(
u in User,
select: fragment("distinct split_part(?, '@', 2)", u.nickname),
where: u.local != ^true
i in Instance
)
|> Repo.all()
|> Enum.filter(& &1)
domain_count = Enum.count(peers)
|> Repo.aggregate(:count, :id)
status_count = Repo.aggregate(User.Query.build(%{local: true}), :sum, :note_count)