feat: add more users counts in /stats/ (#2555)
Some checks are pending
Test & Docs / tests (postgresql, 3.10) (push) Waiting to run
Test & Docs / tests (postgresql, 3.12) (push) Waiting to run
Test & Docs / lint (push) Waiting to run

This commit is contained in:
Yohan Boniface 2025-03-10 16:56:29 +01:00 committed by GitHub
commit 3b195e562a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

@ -185,6 +185,10 @@ def test_stats_empty(client):
"users_count": 0,
"active_sessions": 0,
"version": VERSION,
"editors_count": 0,
"members_count": 0,
"orphans_count": 0,
"owners_count": 0,
}
@ -202,6 +206,10 @@ def test_stats_basic(client, map, datalayer, user2):
"users_count": 2,
"active_sessions": 0,
"version": VERSION,
"editors_count": 0,
"members_count": 0,
"orphans_count": 1,
"owners_count": 1,
}

View file

@ -1372,6 +1372,13 @@ class PictogramJSONList(ListView):
def stats(request):
last_week = make_aware(datetime.now()) - timedelta(days=7)
users = User.objects.values_list("pk", flat=True)
owners = set(
Map.objects.filter(owner__isnull=False).values_list("owner", flat=True)
)
editors = set(Map.editors.through.objects.values_list("user_id", flat=True))
members = set(Team.users.through.objects.values_list("user_id", flat=True))
orphans = set(users) - owners - editors - members
return simple_json_response(
**{
"version": VERSION,
@ -1386,6 +1393,10 @@ def stats(request):
"active_sessions": Session.objects.filter(
expire_date__gt=datetime.utcnow()
).count(),
"owners_count": len(owners),
"editors_count": len(editors),
"members_count": len(members),
"orphans_count": len(orphans),
}
)