Skip to content

Commit f65184b

Browse files
committed
Query message count directly from messages
This was changed due to performance reasons, but after some tweaking in the database, such as increasing work memory and adding an index, this query runs much faster now. To test this, I want to revert this change, so that we can stop the materialised view from refreshing, to see if the act of refreshing is what's causing this query to seem faster when runing against the database.
1 parent b814ec8 commit f65184b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pydis_site/apps/api/models/bot/metricity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ def total_messages(self, user_id: str) -> int:
4646
self.cursor.execute(
4747
"""
4848
SELECT
49-
message_count
50-
FROM user_has_approx_message_count
49+
COUNT(*)
50+
FROM messages
5151
WHERE
5252
author_id = '%s'
53+
AND NOT is_deleted
54+
AND channel_id NOT IN %s
5355
""",
54-
[user_id]
56+
[user_id, EXCLUDE_CHANNELS]
5557
)
5658
values = self.cursor.fetchone()
5759

0 commit comments

Comments
 (0)