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