diff options
author | 2021-11-22 20:36:21 +0000 | |
---|---|---|
committer | 2021-11-22 20:36:21 +0000 | |
commit | 855bf5e7c7e54e9f8e4544545026c47092b52a11 (patch) | |
tree | 3cbad515fb0ee759997ae7d754feaaba6219bbc8 /pydis_site | |
parent | Merge pull request #625 from python-discord/filter-redirects (diff) |
Only calc activity blocks when <1k messages
We only truly care about how many activity blocks a user has when they have a small number of messages, as we only use this for the voice gate.
If a user has more than say 1k messages, then we really don't need to calculate their activity blocks, as it's quite an expensive query with many messages.
Diffstat (limited to 'pydis_site')
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/user.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/user.py b/pydis_site/apps/api/viewsets/bot/user.py index 22d13dc4..ed661323 100644 --- a/pydis_site/apps/api/viewsets/bot/user.py +++ b/pydis_site/apps/api/viewsets/bot/user.py @@ -271,9 +271,15 @@ class UserViewSet(ModelViewSet): with Metricity() as metricity: try: data = metricity.user(user.id) + data["total_messages"] = metricity.total_messages(user.id) + if data["total_messages"] < 1000: + # Only calculate and return activity_blocks if the user has a small amount + # of messages, as calculating activity_blocks is expensive. + # 1000 message chosen as an arbitrarily large number. + data["activity_blocks"] = metricity.total_message_blocks(user.id) + data["voice_banned"] = voice_banned - data["activity_blocks"] = metricity.total_message_blocks(user.id) return Response(data, status=status.HTTP_200_OK) except NotFoundError: return Response(dict(detail="User not found in metricity"), |