Skip to content

Commit 59e4a5c

Browse files
committed
Always include metricity message blocks
Thanks to a recent database maintenance (https://pythondiscord.freshstatus.io/incident/139811) querying out metricity message data is far cheaper. So there is no longer a reason to only fetch blocks if the member has a low message count.
1 parent 2716945 commit 59e4a5c

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

pydis_site/apps/api/tests/test_users.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def setUpTestData(cls):
408408
in_guild=True,
409409
)
410410

411-
def test_get_metricity_data_under_1k(self):
411+
def test_get_metricity_data(self):
412412
# Given
413413
joined_at = "foo"
414414
total_messages = 1
@@ -428,25 +428,6 @@ def test_get_metricity_data_under_1k(self):
428428
"activity_blocks": total_blocks
429429
})
430430

431-
def test_get_metricity_data_over_1k(self):
432-
# Given
433-
joined_at = "foo"
434-
total_messages = 1001
435-
total_blocks = 1001
436-
self.mock_metricity_user(joined_at, total_messages, total_blocks, [])
437-
438-
# When
439-
url = reverse('api:bot:user-metricity-data', args=[0])
440-
response = self.client.get(url)
441-
442-
# Then
443-
self.assertEqual(response.status_code, 200)
444-
self.assertCountEqual(response.json(), {
445-
"joined_at": joined_at,
446-
"total_messages": total_messages,
447-
"voice_banned": False,
448-
})
449-
450431
def test_no_metricity_user(self):
451432
# Given
452433
self.mock_no_metricity_user()

pydis_site/apps/api/viewsets/bot/user.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,7 @@ def metricity_data(self, request: Request, pk: str = None) -> Response:
273273
data = metricity.user(user.id)
274274

275275
data["total_messages"] = metricity.total_messages(user.id)
276-
if data["total_messages"] < 1000:
277-
# Only calculate and return activity_blocks if the user has a small amount
278-
# of messages, as calculating activity_blocks is expensive.
279-
# 1000 message chosen as an arbitrarily large number.
280-
data["activity_blocks"] = metricity.total_message_blocks(user.id)
276+
data["activity_blocks"] = metricity.total_message_blocks(user.id)
281277

282278
data["voice_banned"] = voice_banned
283279
return Response(data, status=status.HTTP_200_OK)

0 commit comments

Comments
 (0)