From 663363b041d7c231f29fd478910a0337eed72b1a Mon Sep 17 00:00:00 2001 From: atrc445 Date: Sun, 22 Aug 2021 13:33:13 +0200 Subject: [PATCH] sort by comments in the database --- files/routes/front.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index b2263f35b..ac1ac01af 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -136,7 +136,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' elif sort == "bottom": posts = sorted(posts.all(), key=lambda x: x.score) elif sort == "comments": - posts = sorted(posts.all(), key=lambda x: x.comment_count, reverse=True) + posts = posts.order_by(Submission.comment_count.desc()).all() elif sort == "random": posts = posts.all() posts = random.sample(posts, k=len(posts)) @@ -424,4 +424,4 @@ def all_comments(v): idlist = idlist[:25] if request.headers.get("Authorization"): return {"data": [x.json for x in comments]} - else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists) \ No newline at end of file + else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists)