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)
16 def schedule_update do
19 Process.sleep(1000 * 60 * 60 * 1) # 1 hour
25 peers = from(u in Pleroma.User,
26 select: fragment("?->'host'", u.info),
27 where: u.local != ^true)
28 |> Repo.all() |> Enum.uniq()
29 domain_count = Enum.count(peers)
30 status_query = from p in Activity,
31 where: p.local == ^true,
32 where: fragment("?->'object'->>'type' = ?", p.data, ^"Note")
33 status_count = Repo.aggregate(status_query, :count, :id)
34 Agent.update(__MODULE__, fn _ ->
35 %{peers: peers, domain_count: domain_count, status_count: status_count}