diff --git a/files/classes/comment.py b/files/classes/comment.py index c12418b20e..6d1f79914d 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -54,7 +54,7 @@ class Comment(Base): author = relationship("User", primaryjoin="User.id==Comment.author_id") senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True) parent_comment = relationship("Comment", remote_side=[id], viewonly=True) - child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True) + child_comments = relationship("Comment", lazy="dynamic", remote_side=[parent_comment_id], viewonly=True) awards = relationship("AwardRelationship", viewonly=True) reports = relationship("CommentFlag", viewonly=True) diff --git a/files/classes/user.py b/files/classes/user.py index b4214b5c18..3f8913c3ed 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 68819bd254..8cc72b9d7e 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,17 +27,18 @@ 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") @auth_required def notifications(v): + t = time.time() try: page = int(request.values.get('page', 1)) except: page = 1 messages = request.values.get('messages') @@ -46,89 +48,98 @@ def notifications(v): if modmail and v.admin_level > 1: comments = g.db.query(Comment).filter(Comment.sentto==2).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() next_exists = (len(comments) > 25) - comments = comments[:25] + listing = comments[:25] elif messages: - comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, not_(Comment.child_comments.any())).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() + comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all() next_exists = (len(comments) > 25) - comments = comments[:25] + listing = comments[:25] elif posts: - notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ID).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all() + notifications = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(Notification.user_id == v.id, Comment.author_id == AUTOJANNY_ID).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all() listing = [] for index, x in enumerate(notifications[:100]): - c = x.comment - if x.read and index > 24: break - elif not x.read: - x.read = True + n, c = x + if n.read and index > 24: break + elif not n.read: + n.read = True c.unread = True - g.db.add(x) - if x.created_utc > 1620391248: c.notif_utc = x.created_utc + g.db.add(n) + if n.created_utc > 1620391248: c.notif_utc = n.created_utc listing.append(c) g.db.commit() next_exists = (len(notifications) > len(listing)) elif reddit: - notifications = v.notifications.join(Notification.comment).filter(Comment.body_html.like('

New rdrama mention: 24: break - elif not x.read: - x.read = True + n, c = x + if n.read and index > 24: break + elif not n.read: + n.read = True c.unread = True - g.db.add(x) - if x.created_utc > 1620391248: c.notif_utc = x.created_utc + g.db.add(n) + if n.created_utc > 1620391248: c.notif_utc = n.created_utc listing.append(c) g.db.commit() next_exists = (len(notifications) > len(listing)) else: - notifications = v.notifications.join(Notification.comment).filter( + unread = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter( + Notification.read == False, + Notification.user_id == v.id, + Comment.author_id != AUTOJANNY_ID, + Comment.body_html.notlike('

New rdrama mention: 50) - notifications = notifications[:50] - cids = [x.comment_id for x in notifications] - comments = get_comments(cids, v=v, load_parent=True) + comments = g.db.query(Comment).join(sq, sq.c.id == Comment.id).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() + + next_exists = (len(comments) > 25) + comments = comments[:25] + + cids = set([x[0] for x in g.db.query(Comment.id).join(Notification).filter( + Notification.user_id == v.id, + Comment.is_banned == False, + Comment.deleted_utc == 0, + Comment.author_id != AUTOJANNY_ID, + Comment.body_html.notlike('

New rdrama mention: {{vote.user.username}} - {{vote.user.truecoins}} + {{vote.user.truecoins}} {% endfor %}

Downvotes

- + + + + {% for vote in downs %} - + + + + {% endfor %}
User
UserUser truescore
{{vote.user.username}}
{{vote.user.username}}{{vote.user.truecoins}}