From 953f232d47ff4e07baeaffa8add7912ff05d6457 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 11 Dec 2021 13:59:40 +0000 Subject: Use new approx message count view We have added a new view to metricity that will keep track of an approximate message count, updating every 10 seconds. By doing this, we avoid running a query against the whole message table every time we want to get a user's messages. --- pydis_site/apps/api/models/bot/metricity.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pydis_site/apps/api/models/bot/metricity.py b/pydis_site/apps/api/models/bot/metricity.py index 901f191a..52e946ac 100644 --- a/pydis_site/apps/api/models/bot/metricity.py +++ b/pydis_site/apps/api/models/bot/metricity.py @@ -46,14 +46,12 @@ class Metricity: self.cursor.execute( """ SELECT - COUNT(*) - FROM messages + message_count + FROM user_has_approx_message_count WHERE author_id = '%s' - AND NOT is_deleted - AND channel_id NOT IN %s """, - [user_id, EXCLUDE_CHANNELS] + [user_id] ) values = self.cursor.fetchone() -- cgit v1.2.3