Merge branch 'fix/2782-nodeinfo-active-users' into 'develop'
nodeinfo: report activeMonth and activeHalfyear users fields Closes #2782 See merge request pleroma/pleroma!3536
This commit is contained in:
commit
235c4139d7
4 changed files with 13 additions and 7 deletions
|
@ -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
|
- Allow users to remove their emails if instance does not need email to register
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- `activeMonth` and `activeHalfyear` fields in NodeInfo usage.users object
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
|
||||||
|
|
|
@ -2474,8 +2474,8 @@ def update_last_active_at(%__MODULE__{local: true} = user) do
|
||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_user_count(weeks \\ 4) do
|
def active_user_count(days \\ 30) do
|
||||||
active_after = Timex.shift(NaiveDateTime.utc_now(), weeks: -weeks)
|
active_after = Timex.shift(NaiveDateTime.utc_now(), days: -days)
|
||||||
|
|
||||||
__MODULE__
|
__MODULE__
|
||||||
|> where([u], u.last_active_at >= ^active_after)
|
|> where([u], u.last_active_at >= ^active_after)
|
||||||
|
|
|
@ -35,7 +35,9 @@ def get_nodeinfo("2.0") do
|
||||||
openRegistrations: Config.get([:instance, :registrations_open]),
|
openRegistrations: Config.get([:instance, :registrations_open]),
|
||||||
usage: %{
|
usage: %{
|
||||||
users: %{
|
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)
|
localPosts: Map.get(stats, :status_count, 0)
|
||||||
},
|
},
|
||||||
|
|
|
@ -2410,13 +2410,16 @@ test "update_last_active_at/1" do
|
||||||
test "active_user_count/1" do
|
test "active_user_count/1" do
|
||||||
insert(:user)
|
insert(:user)
|
||||||
insert(:user, %{local: false})
|
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: 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() == 2
|
||||||
assert User.active_user_count(6) == 3
|
assert User.active_user_count(180) == 3
|
||||||
assert User.active_user_count(1) == 1
|
assert User.active_user_count(365) == 4
|
||||||
|
assert User.active_user_count(1000) == 5
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "pins" do
|
describe "pins" do
|
||||||
|
|
Loading…
Reference in a new issue