devrana
This commit is contained in:
parent
94ee955ca0
commit
59bca34ed0
1 changed files with 44 additions and 19 deletions
|
@ -19,7 +19,7 @@ def clear(v):
|
|||
@app.get("/unread")
|
||||
@auth_required
|
||||
def unread(v):
|
||||
listing = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
||||
listing = g.db.query(Notification, Comment).filter(
|
||||
Notification.read == False,
|
||||
Notification.user_id == v.id,
|
||||
Comment.is_banned == False,
|
||||
|
@ -54,7 +54,7 @@ def notifications(v):
|
|||
next_exists = (len(comments) > 25)
|
||||
listing = comments[:25]
|
||||
elif posts:
|
||||
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()
|
||||
notifications = g.db.query(Notification, Comment).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 = []
|
||||
|
||||
|
@ -72,7 +72,7 @@ def notifications(v):
|
|||
|
||||
next_exists = (len(notifications) > len(listing))
|
||||
elif reddit:
|
||||
notifications = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(Notification.user_id == v.id, Comment.body_html.like('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
|
||||
notifications = g.db.query(Notification, Comment).filter(Notification.user_id == v.id, Comment.body_html.like('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
|
||||
|
||||
listing = []
|
||||
|
||||
|
@ -90,7 +90,7 @@ def notifications(v):
|
|||
|
||||
next_exists = (len(notifications) > len(listing))
|
||||
else:
|
||||
unread = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
||||
unread = g.db.query(Notification, Comment).filter(
|
||||
Notification.read == False,
|
||||
Notification.user_id == v.id,
|
||||
Comment.author_id != AUTOJANNY_ID,
|
||||
|
@ -102,7 +102,10 @@ def notifications(v):
|
|||
g.db.add(c)
|
||||
g.db.commit()
|
||||
|
||||
sq = g.db.query(Comment.id, Notification.created_utc).join(Notification).distinct(Comment.top_comment_id).filter(
|
||||
print("1: " + str(time.time()-t))
|
||||
t = time.time()
|
||||
|
||||
sq = g.db.query(Comment.id, Notification.created_utc).distinct(Comment.top_comment_id).filter(
|
||||
Notification.user_id == v.id,
|
||||
Comment.is_banned == False,
|
||||
Comment.deleted_utc == 0,
|
||||
|
@ -110,35 +113,56 @@ def notifications(v):
|
|||
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
|
||||
).order_by(Comment.top_comment_id.desc(), Notification.created_utc.desc()).subquery()
|
||||
|
||||
print("2: " + str(time.time()-t))
|
||||
t = time.time()
|
||||
|
||||
comments = g.db.query(Comment).join(sq, sq.c.id == Comment.id).order_by(sq.c.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
|
||||
|
||||
print("3: " + str(time.time()-t))
|
||||
t = time.time()
|
||||
|
||||
next_exists = (len(comments) > 25)
|
||||
comments = comments[:25]
|
||||
|
||||
cids = [x[0] for x in g.db.query(Comment.id).join(Notification).filter(
|
||||
all = g.db.query(Comment, Notification.created_utc).filter(
|
||||
Notification.user_id == v.id,
|
||||
Comment.is_banned == False,
|
||||
Comment.deleted_utc == 0,
|
||||
Comment.author_id != AUTOJANNY_ID,
|
||||
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
|
||||
).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(500).all()]
|
||||
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%'),
|
||||
Comment.parent_submission != None
|
||||
).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(500).all()
|
||||
|
||||
comms = get_comments(cids, v=v)
|
||||
print("4: " + str(time.time()-t))
|
||||
t = time.time()
|
||||
|
||||
comms = get_comments([x[0].id for x in all], v=v)
|
||||
|
||||
|
||||
listing = []
|
||||
|
||||
print("5: " + str(time.time()-t))
|
||||
t = time.time()
|
||||
|
||||
for c, n in all:
|
||||
if n > 1620391248: c.notif_utc = n
|
||||
|
||||
if c.parent_submission:
|
||||
if c.replies2 == None: c.replies2 = []
|
||||
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment in all):
|
||||
parent = c.parent_comment
|
||||
if parent.replies2 == None: parent.replies2 = [c]
|
||||
elif c not in parent.replies2: parent.replies2.append(c)
|
||||
c = parent
|
||||
|
||||
if c.replies2 == None: c.replies2 = []
|
||||
|
||||
print("6: " + str(time.time()-t))
|
||||
t = time.time()
|
||||
|
||||
for c in comments:
|
||||
if c.parent_submission:
|
||||
if c.replies2 == None:
|
||||
c.replies2 = c.child_comments.filter(or_(Comment.author_id == v.id, Comment.id.in_(cids))).all()
|
||||
for x in c.replies2:
|
||||
if x.replies2 == None: x.replies2 = []
|
||||
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment.id in cids):
|
||||
c = c.parent_comment
|
||||
if c.replies2 == None:
|
||||
c.replies2 = c.child_comments.filter(or_(Comment.author_id == v.id, Comment.id.in_(cids))).all()
|
||||
for x in c.replies2:
|
||||
if x.replies2 == None: x.replies2 = []
|
||||
else:
|
||||
while c.parent_comment:
|
||||
c = c.parent_comment
|
||||
|
@ -146,7 +170,8 @@ def notifications(v):
|
|||
|
||||
if c not in listing: listing.append(c)
|
||||
|
||||
print(time.time() - t)
|
||||
print("7: " + str(time.time()-t))
|
||||
|
||||
if request.headers.get("Authorization"): return {"data":[x.json for x in listing]}
|
||||
|
||||
return render_template("notifications.html",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue