1 defmodule Pleroma.Stats do
4 alias Pleroma.{User, Repo, Activity}
7 agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
13 Agent.get(__MODULE__, fn {_, stats} -> stats end)
17 Agent.get(__MODULE__, fn {peers, _} -> peers end)
20 def schedule_update do
23 Process.sleep(1000 * 60 * 60 * 1) # 1 hour
29 peers = from(u in Pleroma.User,
30 select: fragment("?->'host'", u.info),
31 where: u.local != ^true)
32 |> Repo.all() |> Enum.uniq()
33 domain_count = Enum.count(peers)
34 status_query = from p in Activity,
35 where: p.local == ^true,
36 where: fragment("?->'object'->>'type' = ?", p.data, ^"Note")
37 status_count = Repo.aggregate(status_query, :count, :id)
38 user_count = Repo.aggregate(User.local_user_query, :count, :id)
39 Agent.update(__MODULE__, fn _ ->
40 {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}