Merge branch 'fix/2782-nodeinfo-active-users' into 'develop'
authorlain <lain@soykaf.club>
Thu, 2 Dec 2021 16:54:28 +0000 (16:54 +0000)
committerlain <lain@soykaf.club>
Thu, 2 Dec 2021 16:54:28 +0000 (16:54 +0000)
nodeinfo: report activeMonth and activeHalfyear users fields

Closes #2782

See merge request pleroma/pleroma!3536

CHANGELOG.md
lib/pleroma/user.ex
lib/pleroma/web/nodeinfo/nodeinfo.ex
test/pleroma/user_test.exs

index decf9ef471a74d66b96b7576f73856204deab9cc..ecefba381da76f255e2d43a19a22b21270ea0d5c 100644 (file)
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Allow users to remove their emails if instance does not need email to register
 
 ### Added
+- `activeMonth` and `activeHalfyear` fields in NodeInfo usage.users object
 
 ### Fixed
 - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
index 3b4e49176c65232edf07a67196f53875464c3457..8e40dfc0d846b55ee67dfcc6b8c482060a99a6a7 100644 (file)
@@ -2474,8 +2474,8 @@ defmodule Pleroma.User do
     |> update_and_set_cache()
   end
 
-  def active_user_count(weeks \\ 4) do
-    active_after = Timex.shift(NaiveDateTime.utc_now(), weeks: -weeks)
+  def active_user_count(days \\ 30) do
+    active_after = Timex.shift(NaiveDateTime.utc_now(), days: -days)
 
     __MODULE__
     |> where([u], u.last_active_at >= ^active_after)
index 6a0112d2a2c1304874f8b54c2155dfd4a7c5a0b1..3781781c849ae3ad8618bd0c8ddc00edd2fb5f8d 100644 (file)
@@ -35,7 +35,9 @@ defmodule Pleroma.Web.Nodeinfo.Nodeinfo do
       openRegistrations: Config.get([:instance, :registrations_open]),
       usage: %{
         users: %{
-          total: Map.get(stats, :user_count, 0)
+          total: Map.get(stats, :user_count, 0),
+          activeMonth: Pleroma.User.active_user_count(30),
+          activeHalfyear: Pleroma.User.active_user_count(180)
         },
         localPosts: Map.get(stats, :status_count, 0)
       },
index 5fef81245b0af61959f4060cf2c124ab4ab70eb0..12d5d5db6869c969def860bfff49765cc6c394bf 100644 (file)
@@ -2410,13 +2410,16 @@ defmodule Pleroma.UserTest do
   test "active_user_count/1" do
     insert(:user)
     insert(:user, %{local: false})
-    insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -5)})
-    insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -3)})
     insert(:user, %{last_active_at: NaiveDateTime.utc_now()})
+    insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), days: -15)})
+    insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -6)})
+    insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), months: -7)})
+    insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), years: -2)})
 
     assert User.active_user_count() == 2
-    assert User.active_user_count(6) == 3
-    assert User.active_user_count(1) == 1
+    assert User.active_user_count(180) == 3
+    assert User.active_user_count(365) == 4
+    assert User.active_user_count(1000) == 5
   end
 
   describe "pins" do