mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 08:39:24 +02:00
Include user activity stats in nodeinfo endpoints
This commit is contained in:
parent
e8c81d734f
commit
0b66737181
4 changed files with 30 additions and 9 deletions
|
@ -17,7 +17,7 @@ def get():
|
|||
"protocols": ["activitypub"],
|
||||
"services": {"inbound": [], "outbound": []},
|
||||
"openRegistrations": preferences.get("users__registration_enabled"),
|
||||
"usage": {"users": {"total": 0}},
|
||||
"usage": {"users": {"total": 0, "activeHalfyear": 0, "activeMonth": 0}},
|
||||
"metadata": {
|
||||
"private": preferences.get("instance__nodeinfo_private"),
|
||||
"shortDescription": preferences.get("instance__short_description"),
|
||||
|
@ -37,7 +37,11 @@ def get():
|
|||
if share_stats:
|
||||
getter = memo(lambda: stats.get(), max_age=600)
|
||||
statistics = getter()
|
||||
data["usage"]["users"]["total"] = statistics["users"]
|
||||
data["usage"]["users"]["total"] = statistics["users"]["total"]
|
||||
data["usage"]["users"]["activeHalfyear"] = statistics["users"][
|
||||
"active_halfyear"
|
||||
]
|
||||
data["usage"]["users"]["activeMonth"] = statistics["users"]["active_month"]
|
||||
data["metadata"]["library"]["tracks"] = {"total": statistics["tracks"]}
|
||||
data["metadata"]["library"]["artists"] = {"total": statistics["artists"]}
|
||||
data["metadata"]["library"]["albums"] = {"total": statistics["albums"]}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import datetime
|
||||
|
||||
from django.db.models import Sum
|
||||
from django.utils import timezone
|
||||
|
||||
from funkwhale_api.favorites.models import TrackFavorite
|
||||
from funkwhale_api.history.models import Listening
|
||||
|
@ -19,6 +22,15 @@ def get():
|
|||
|
||||
|
||||
def get_users():
|
||||
qs = User.objects.filter(is_active=True)
|
||||
now = timezone.now()
|
||||
active_month = now - datetime.timedelta(days=30)
|
||||
active_halfyear = now - datetime.timedelta(days=30 * 6)
|
||||
return {
|
||||
"total": qs.count(),
|
||||
"active_month": qs.filter(last_activity__gte=active_month).count(),
|
||||
"active_halfyear": qs.filter(last_activity__gte=active_halfyear).count(),
|
||||
}
|
||||
return User.objects.count()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue