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
12 @interval 1000 * 60 * 60
15 GenServer.start_link(__MODULE__, initial_data(), name: __MODULE__)
19 GenServer.call(__MODULE__, :force_update)
23 %{stats: stats} = GenServer.call(__MODULE__, :get_state)
29 %{peers: peers} = GenServer.call(__MODULE__, :get_state)
35 Process.send(self(), :run_update, [])
39 def handle_call(:force_update, _from, _state) do
40 new_stats = get_stat_data()
41 {:reply, new_stats, new_stats}
44 def handle_call(:get_state, _from, state) do
45 {:reply, state, state}
48 def handle_info(:run_update, _state) do
49 new_stats = get_stat_data()
51 Process.send_after(self(), :run_update, @interval)
56 %{peers: [], stats: %{}}
63 select: fragment("distinct split_part(?, '@', 2)", u.nickname),
64 where: u.local != ^true
69 domain_count = Enum.count(peers)
72 from(u in User.Query.build(%{local: true}),
73 select: fragment("sum((?->>'note_count')::int)", u.info)
76 status_count = Repo.one(status_query)
78 user_count = Repo.aggregate(User.Query.build(%{local: true, active: true}), :count, :id)
82 stats: %{domain_count: domain_count, status_count: status_count, user_count: user_count}