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
11 agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
12 spawn(fn -> schedule_update() end)
17 Agent.get(__MODULE__, fn {_, stats} -> stats end)
21 Agent.get(__MODULE__, fn {peers, _} -> peers end)
24 def schedule_update do
27 Process.sleep(1000 * 60 * 60)
38 select: fragment("distinct split_part(?, '@', 2)", u.nickname),
39 where: u.local != ^true
44 domain_count = Enum.count(peers)
47 from(u in User.Query.build(%{local: true}),
48 select: fragment("sum((?->>'note_count')::int)", u.info)
51 status_count = Repo.one(status_query)
53 user_count = Repo.aggregate(User.Query.build(%{local: true, active: true}), :count, :id)
55 Agent.update(__MODULE__, fn _ ->
56 {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}