1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Stats do
13 agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
14 spawn(fn -> schedule_update() end)
19 Agent.get(__MODULE__, fn {_, stats} -> stats end)
23 Agent.get(__MODULE__, fn {peers, _} -> peers end)
26 def schedule_update do
29 Process.sleep(1000 * 60 * 60)
40 select: fragment("distinct split_part(?, '@', 2)", u.nickname),
41 where: u.local != ^true
46 domain_count = Enum.count(peers)
49 from(u in User.Query.build(%{local: true}),
50 select: fragment("sum((?->>'note_count')::int)", u.info)
53 status_count = Repo.one(status_query)
55 user_count = Repo.aggregate(User.Query.build(%{local: true, active: true}), :count, :id)
57 Agent.update(__MODULE__, fn _ ->
58 {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}