Merge pull request 'docs: fedora install errata' (#398) from acuteaura/akkoma:acuteau...
[akkoma] / lib / pleroma / stats.ex
index b096a9b1e8ea43a0a3fa958eafcaf2a9262829eb..c47a0f9defc10845f16df145667151824cb0998c 100644 (file)
@@ -11,7 +11,7 @@ defmodule Pleroma.Stats do
   alias Pleroma.Repo
   alias Pleroma.User
 
-  @interval :timer.seconds(60)
+  @interval :timer.seconds(300)
 
   def start_link(_) do
     GenServer.start_link(
@@ -23,7 +23,11 @@ defmodule Pleroma.Stats do
 
   @impl true
   def init(_args) do
-    {:ok, nil, {:continue, :calculate_stats}}
+    if Pleroma.Config.get(:env) != :test do
+      {:ok, nil, {:continue, :calculate_stats}}
+    else
+      {:ok, calculate_stat_data()}
+    end
   end
 
   @doc "Performs update stats"
@@ -81,14 +85,24 @@ defmodule Pleroma.Stats do
         where: not u.invisible
       )
 
+    remote_users_query =
+      from(u in User,
+        where: u.is_active == true,
+        where: u.local == false,
+        where: not is_nil(u.nickname),
+        where: not u.invisible
+      )
+
     user_count = Repo.aggregate(users_query, :count, :id)
+    remote_user_count = Repo.aggregate(remote_users_query, :count, :id)
 
     %{
       peers: peers,
       stats: %{
         domain_count: domain_count,
         status_count: status_count || 0,
-        user_count: user_count
+        user_count: user_count,
+        remote_user_count: remote_user_count
       }
     }
   end