From f797a50010dd7d9eaf9659e12531b8270a67b3b9 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 2 Mar 2024 12:14:11 +0200 Subject: [PATCH] fix 500 error when no keyword notifs are present --- files/classes/user.py | 7 ------- files/helpers/alerts.py | 8 ++++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 67b68af97..3a9777db1 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -1169,13 +1169,6 @@ class User(Base): l = [i for i in l if i] return l - @property - @lazy - def notif_words(self): - l = self.keyword_notifs.lower().split('\n') - l = [i for i in l if i] - return l - @property @lazy def lottery_stats(self): diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 07d03ade6..c81671d73 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -153,12 +153,12 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr criteria = (Notification.user_id == User.id, Notification.read == False) - keyword_users = g.db.query(User).options(load_only(User.id, User.keyword_notifs)).outerjoin(Notification, and_(*criteria)).group_by(User.id).having(func.count(Notification.user_id) < 100).filter(User.keyword_notifs != None) + keyword_users = g.db.query(User.id, User.keyword_notifs).outerjoin(Notification, and_(*criteria)).group_by(User.id, User.keyword_notifs).having(func.count(Notification.user_id) < 100).filter(User.keyword_notifs != None) - for user in keyword_users: - for word in user.notif_words: + for id, keyword_notifs in keyword_users: + for word in keyword_notifs.lower().split('\n'): if word in text: - notify_users.add(user.id) + notify_users.add(id) names = set(m.group(1) for m in mention_regex.finditer(text))