From 8d00769ef4a86db275fd83019f35a0cd56bb06ab Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 5 May 2023 03:35:56 +0300 Subject: [PATCH] load only what u need when clearing notifs --- files/routes/notifications.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 6755c237c..86084de86 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -1,6 +1,7 @@ import time from sqlalchemy.sql.expression import not_, and_, or_ +from sqlalchemy.orm import load_only from files.classes.mod_logs import ModAction from files.classes.sub_logs import SubAction @@ -17,10 +18,15 @@ from files.__main__ import app @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @auth_required def clear(v): - notifs = g.db.query(Notification).join(Notification.comment).filter(Notification.read == False, Notification.user_id == v.id).all() + notifs = g.db.query(Notification).join(Notification.comment).filter( + Notification.read == False, + Notification.user_id == v.id, + ).options(load_only(Notification.id)).all() + for n in notifs: n.read = True g.db.add(n) + v.last_viewed_post_notifs = int(time.time()) v.last_viewed_log_notifs = int(time.time()) v.last_viewed_reddit_notifs = int(time.time()) @@ -298,12 +304,12 @@ def notifications(v:User): Comment.is_banned != False, Comment.deleted_utc != 0, ) - ).all() + ).options(load_only(Notification.id)).all() for n in unread_and_inaccessible: n.read = True g.db.add(n) - comments = g.db.query(Comment, Notification).join(Notification.comment).filter( + comments = g.db.query(Comment, Notification).options(load_only(Comment.id)).join(Notification.comment).filter( Notification.user_id == v.id, or_(Comment.sentto == None, Comment.sentto != v.id), )