From 67d9629eac72b81e2ebd54d6265138e89b6bac2e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 4 Apr 2022 01:21:06 +0200 Subject: [PATCH] fds --- files/classes/user.py | 5 ----- files/routes/front.py | 15 +++++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index b4214b5c1..3f8913c3e 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -187,11 +187,6 @@ class User(Base): def csslazy(self): return self.css - @property - @lazy - def notifications(self): - return g.db.query(Notification).filter_by(user_id=self.id) - @property @lazy def created_date(self): diff --git a/files/routes/front.py b/files/routes/front.py index 861c6b61c..34abb8384 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -9,7 +9,8 @@ defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip() @app.post("/clear") @auth_required def clear(v): - for n in v.notifications.filter_by(read=False).all(): + notifs = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(Notification.read == False, Notification.user_id == v.id).all() + for n in notifs: n.read = True g.db.add(n) g.db.commit() @@ -18,7 +19,7 @@ def clear(v): @app.get("/unread") @auth_required def unread(v): - listing = g.db.query(Comment).join(Notification.comment).filter( + listing = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter( Notification.read == False, Notification.user_id == v.id, Comment.is_banned == False, @@ -26,12 +27,12 @@ def unread(v): Comment.author_id != AUTOJANNY_ID, ).order_by(Notification.created_utc.desc()).all() - for n in v.notifications.filter_by(read=False).all(): + for n, c in listing: n.read = True g.db.add(n) g.db.commit() - return {"data":[x.json for x in listing]} + return {"data":[x[1].json for x in listing]} @app.get("/notifications") @@ -58,7 +59,8 @@ def notifications(v): listing = [] - for index, n. c in enumerate(notifications[:100]): + for index, x in enumerate(notifications[:100]): + n, c = x if n.read and index > 24: break elif not n.read: n.read = True @@ -75,7 +77,8 @@ def notifications(v): listing = [] - for index, n, c in enumerate(notifications[:100]): + for index, x in enumerate(notifications[:100]): + n, c = x if n.read and index > 24: break elif not n.read: n.read = True