aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2023-05-12 10:32:44 +0200
committerGravatar GitHub <[email protected]>2023-05-12 10:32:44 +0200
commita4531f529867d833b47c3bf9bcbd48e029f17bfa (patch)
tree19c066ba53319e789c465d57091f5fdd7f794f45
parentMerge pull request #969 from python-discord/psycopg3 (diff)
parentFix psycopg3 compatibility in metricity (diff)
Merge pull request #972 from python-discord/fix-psycopg3-compatibility-in-metricity
Fix psycopg3 compatibility in metricity
-rw-r--r--pydis_site/apps/api/models/bot/metricity.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/pydis_site/apps/api/models/bot/metricity.py b/pydis_site/apps/api/models/bot/metricity.py
index a55f5e5b..f1277b21 100644
--- a/pydis_site/apps/api/models/bot/metricity.py
+++ b/pydis_site/apps/api/models/bot/metricity.py
@@ -3,10 +3,11 @@ from django.db import connections
BLOCK_INTERVAL = 10 * 60 # 10 minute blocks
-EXCLUDE_CHANNELS = (
+# This needs to be a list due to psycopg3 type adaptions.
+EXCLUDE_CHANNELS = [
"267659945086812160", # Bot commands
"607247579608121354" # SeasonalBot commands
-)
+]
class NotFoundError(Exception):
@@ -48,7 +49,7 @@ class Metricity:
WHERE
author_id = '%s'
AND NOT is_deleted
- AND channel_id NOT IN %s
+ AND channel_id != ANY(%s)
""",
[user_id, EXCLUDE_CHANNELS]
)
@@ -76,7 +77,7 @@ class Metricity:
WHERE
author_id='%s'
AND NOT is_deleted
- AND channel_id NOT IN %s
+ AND channel_id != ANY(%s)
GROUP BY interval
) block_query;
""",
@@ -144,13 +145,13 @@ class Metricity:
author_id, COUNT(*)
FROM messages
WHERE
- author_id IN %s
+ author_id = ANY(%s)
AND NOT is_deleted
- AND channel_id NOT IN %s
+ AND channel_id != ANY(%s)
AND created_at > now() - interval '%s days'
GROUP BY author_id
""",
- [tuple(user_ids), EXCLUDE_CHANNELS, days]
+ [user_ids, EXCLUDE_CHANNELS, days]
)
values = self.cursor.fetchall()