From 3d971c136850f2ea0a0d5404db2a50ca04b8163c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 6 Dec 2021 00:52:39 +0200 Subject: [PATCH] sfdfds --- files/routes/posts.py | 32 ++++++++++++++++++++++++++----- files/templates/comments.html | 8 ++++++++ files/templates/submission.html | 34 +-------------------------------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 7d068a0449..d08357e951 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -190,7 +190,7 @@ def post_id(pid, anything=None, v=None): offset = 0 - if post.comment_count > 60: + if len(comments) > 60: comments2 = [] count = 0 if post.created_utc > 1638672040: @@ -229,6 +229,7 @@ def post_id(pid, anything=None, v=None): @limiter.limit("1/second") @auth_desired def viewmore(v, pid, sort, offset): + offset = int(offset) if v: votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() @@ -283,7 +284,7 @@ def viewmore(v, pid, sort, offset): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - if offset: comments = comments.offset(int(offset)) + comments = comments.offset(offset) comments = [c[0] for c in comments.all()] else: @@ -300,11 +301,32 @@ def viewmore(v, pid, sort, offset): elif sort == "bottom": comments = comments.order_by(Comment.upvotes - Comment.downvotes) - if offset: comments = comments.offset(int(offset)) - + comments = comments.offset(offset) + comments = comments.all() - return render_template("comments.html", v=v, comments=comments, render_replies=True) + if len(comments) > 60: + comments2 = [] + count = 0 + post = get_post(pid, v=v) + if post.created_utc > 1638672040: + for comment in comments: + comments2.append(comment) + count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1 + offset += 1 + if count > 50: break + else: + for comment in comments: + comments2.append(comment) + count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1 + offset += 1 + if count > 10: break + + if len(comments) == len(comments2): offset = None + comments = comments2 + else: offset = None + + return render_template("comments.html", v=v, comments=comments, render_replies=True, pid=pid, sort=sort, offset=offset) @app.post("/edit_post/") diff --git a/files/templates/comments.html b/files/templates/comments.html index 5309c42276..c0c652f7b9 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -800,4 +800,12 @@ {% endif %} +{% if offset %} + {% if p %} + {% set pid = p.id %} + {% endif %} +
+
+{% endif %} + \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index cc6bc70098..23f24ac6df 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -825,39 +825,7 @@ {% if offset %} - -
-
+ {% endif %}