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
29 @doc "Performs update stats"
31 GenServer.call(__MODULE__, :force_update)
34 @doc "Performs collect stats"
36 GenServer.cast(__MODULE__, :run_update)
39 @doc "Returns stats data"
40 @spec get_stats() :: %{domain_count: integer(), status_count: integer(), user_count: integer()}
42 %{stats: stats} = GenServer.call(__MODULE__, :get_state)
47 @doc "Returns list peers"
48 @spec get_peers() :: list(String.t())
50 %{peers: peers} = GenServer.call(__MODULE__, :get_state)
59 def handle_call(:force_update, _from, _state) do
60 new_stats = get_stat_data()
61 {:reply, new_stats, new_stats}
64 def handle_call(:get_state, _from, state) do
65 {:reply, state, state}
68 def handle_cast(:run_update, _state) do
69 new_stats = get_stat_data()
78 select: fragment("distinct split_part(?, '@', 2)", u.nickname),
79 where: u.local != ^true
84 domain_count = Enum.count(peers)
86 status_count = Repo.aggregate(User.Query.build(%{local: true}), :sum, :note_count)
88 user_count = Repo.aggregate(User.Query.build(%{local: true, active: true}), :count, :id)
93 domain_count: domain_count,
94 status_count: status_count,
95 user_count: user_count