1 defmodule Pleroma.Stats do
3 alias Pleroma.{User, Repo}
6 agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
7 spawn(fn -> schedule_update() end)
12 Agent.get(__MODULE__, fn {_, stats} -> stats end)
16 Agent.get(__MODULE__, fn {peers, _} -> peers end)
19 def schedule_update do
22 Process.sleep(1000 * 60 * 60 * 1)
33 select: fragment("distinct ?->'host'", u.info),
34 where: u.local != ^true
38 domain_count = Enum.count(peers)
41 from(u in User.local_user_query(), select: fragment("sum((?->>'note_count')::int)", u.info))
43 status_count = Repo.one(status_query)
44 user_count = Repo.aggregate(User.local_user_query(), :count, :id)
46 Agent.update(__MODULE__, fn _ ->
47 {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}