sdf
parent
6acd03e103
commit
7156f216e4
|
@ -9,7 +9,7 @@ defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip()
|
||||||
@app.post("/clear")
|
@app.post("/clear")
|
||||||
@auth_required
|
@auth_required
|
||||||
def clear(v):
|
def clear(v):
|
||||||
notifs = g.db.query(Notification).join(Comment, Notification.comment_id == Comment.id).filter(Notification.read == False, Notification.user_id == v.id).all()
|
notifs = g.db.query(Notification).join(Comment).filter(Notification.read == False, Notification.user_id == v.id).all()
|
||||||
for n in notifs:
|
for n in notifs:
|
||||||
n.read = True
|
n.read = True
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
|
@ -19,7 +19,7 @@ def clear(v):
|
||||||
@app.get("/unread")
|
@app.get("/unread")
|
||||||
@auth_required
|
@auth_required
|
||||||
def unread(v):
|
def unread(v):
|
||||||
listing = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
listing = g.db.query(Notification, Comment).join(Comment).filter(
|
||||||
Notification.read == False,
|
Notification.read == False,
|
||||||
Notification.user_id == v.id,
|
Notification.user_id == v.id,
|
||||||
Comment.is_banned == False,
|
Comment.is_banned == False,
|
||||||
|
@ -38,6 +38,7 @@ def unread(v):
|
||||||
@app.get("/notifications")
|
@app.get("/notifications")
|
||||||
@auth_required
|
@auth_required
|
||||||
def notifications(v):
|
def notifications(v):
|
||||||
|
sex = time.time()
|
||||||
t = time.time()
|
t = time.time()
|
||||||
try: page = int(request.values.get('page', 1))
|
try: page = int(request.values.get('page', 1))
|
||||||
except: page = 1
|
except: page = 1
|
||||||
|
@ -54,7 +55,7 @@ def notifications(v):
|
||||||
next_exists = (len(comments) > 25)
|
next_exists = (len(comments) > 25)
|
||||||
listing = comments[:25]
|
listing = comments[:25]
|
||||||
elif posts:
|
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).join(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 = []
|
listing = []
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ def notifications(v):
|
||||||
|
|
||||||
next_exists = (len(notifications) > len(listing))
|
next_exists = (len(notifications) > len(listing))
|
||||||
elif reddit:
|
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).join(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 = []
|
listing = []
|
||||||
|
|
||||||
|
@ -90,19 +91,10 @@ def notifications(v):
|
||||||
|
|
||||||
next_exists = (len(notifications) > len(listing))
|
next_exists = (len(notifications) > len(listing))
|
||||||
else:
|
else:
|
||||||
unread = g.db.query(Notification, Comment).join(Comment, Notification.comment_id == Comment.id).filter(
|
print("1: " + str(time.time()-t))
|
||||||
Notification.read == False,
|
t = time.time()
|
||||||
Notification.user_id == v.id,
|
|
||||||
Comment.author_id != AUTOJANNY_ID,
|
|
||||||
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%'))
|
|
||||||
|
|
||||||
for n, c in unread:
|
sq = g.db.query(Comment.id, Notification.created_utc).join(Notification, Notification.comment_id == Comment.id).distinct(Comment.top_comment_id).filter(
|
||||||
n.read = True
|
|
||||||
c.unread = True
|
|
||||||
g.db.add(c)
|
|
||||||
g.db.commit()
|
|
||||||
|
|
||||||
sq = g.db.query(Comment.id, Notification.created_utc).join(Notification).distinct(Comment.top_comment_id).filter(
|
|
||||||
Notification.user_id == v.id,
|
Notification.user_id == v.id,
|
||||||
Comment.is_banned == False,
|
Comment.is_banned == False,
|
||||||
Comment.deleted_utc == 0,
|
Comment.deleted_utc == 0,
|
||||||
|
@ -112,32 +104,45 @@ def notifications(v):
|
||||||
|
|
||||||
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()
|
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("2: " + str(time.time()-t))
|
||||||
|
t = time.time()
|
||||||
|
|
||||||
next_exists = (len(comments) > 25)
|
next_exists = (len(comments) > 25)
|
||||||
comments = comments[:25]
|
comments = comments[:25]
|
||||||
|
|
||||||
cids = set([x[0] for x in g.db.query(Comment.id).join(Notification).filter(
|
all = g.db.query(Comment).join(Notification, Notification.comment_id == Comment.id).filter(
|
||||||
Notification.user_id == v.id,
|
Notification.user_id == v.id,
|
||||||
Comment.is_banned == False,
|
Comment.is_banned == False,
|
||||||
Comment.deleted_utc == 0,
|
Comment.deleted_utc == 0,
|
||||||
Comment.author_id != AUTOJANNY_ID,
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
Comment.body_html.notlike('<html><body><p>New rdrama mention: <a href="https://old.reddit.com/r/%')
|
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(100).all()])
|
Comment.parent_submission != None
|
||||||
|
).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(100).all()
|
||||||
|
|
||||||
comms = get_comments(list(cids), v=v)
|
print("3: " + str(time.time()-t))
|
||||||
|
t = time.time()
|
||||||
|
|
||||||
|
cids = [x.id for x in all]
|
||||||
|
comms = get_comments(cids, v=v)
|
||||||
listing = []
|
listing = []
|
||||||
|
|
||||||
|
print("4: " + str(time.time()-t))
|
||||||
|
t = time.time()
|
||||||
|
|
||||||
|
for c in all:
|
||||||
|
c.replies2 = []
|
||||||
|
parent = c.parent_comment
|
||||||
|
if parent:
|
||||||
|
if not parent.replies2: parent.replies2 = [c]
|
||||||
|
else: parent.replies2.append(c)
|
||||||
|
|
||||||
|
print("5: " + str(time.time()-t))
|
||||||
|
t = time.time()
|
||||||
|
|
||||||
for c in comments:
|
for c in comments:
|
||||||
if c.parent_submission:
|
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):
|
while c.parent_comment and (c.parent_comment.author_id == v.id or c.parent_comment.id in cids):
|
||||||
c = c.parent_comment
|
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:
|
else:
|
||||||
while c.parent_comment:
|
while c.parent_comment:
|
||||||
c = c.parent_comment
|
c = c.parent_comment
|
||||||
|
@ -145,7 +150,9 @@ def notifications(v):
|
||||||
|
|
||||||
if c not in listing: listing.append(c)
|
if c not in listing: listing.append(c)
|
||||||
|
|
||||||
print("all: " + str(time.time()-t))
|
print("6: " + str(time.time()-t))
|
||||||
|
|
||||||
|
print("all: " + str(time.time()-sex))
|
||||||
|
|
||||||
if request.headers.get("Authorization"): return {"data":[x.json for x in listing]}
|
if request.headers.get("Authorization"): return {"data":[x.json for x in listing]}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue