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
7 alias Pleroma.{User, Repo}
10 agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__)
11 spawn(fn -> schedule_update() end)
16 Agent.get(__MODULE__, fn {_, stats} -> stats end)
20 Agent.get(__MODULE__, fn {peers, _} -> peers end)
23 def schedule_update do
26 Process.sleep(1000 * 60 * 60 * 1)
37 select: fragment("distinct ?->'host'", u.info),
38 where: u.local != ^true
42 domain_count = Enum.count(peers)
45 from(u in User.local_user_query(), select: fragment("sum((?->>'note_count')::int)", u.info))
47 status_count = Repo.one(status_query)
48 user_count = Repo.aggregate(User.local_user_query(), :count, :id)
50 Agent.update(__MODULE__, fn _ ->
51 {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}