diff --git a/files/classes/user.py b/files/classes/user.py index 576c186f8..f8ba04880 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -193,7 +193,7 @@ class User(Base, Stndrd, Age_times): elif sort == "bottom": submissions = sorted(submissions.all(), key=lambda x: x.score) elif sort == "comments": - submissions = sorted(submissions.all(), key=lambda x: x.comment_count, reverse=True) + submissions = submissions.order_by(Submission.comment_count.desc()).all() firstrange = 25 * (page - 1) secondrange = firstrange + 26 diff --git a/files/routes/posts.py b/files/routes/posts.py index 257917a20..811c407fd 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -884,9 +884,6 @@ def submit_post(v): g.db.add(c) g.db.flush() - new_post.comment_count = g.db.query(Comment).filter_by(parent_submission=new_post.id).count() - g.db.add(new_post) - if "rdrama" in request.host: if v.id == 995: body = "fuck off carp" else: body = random.choice(snappyquotes) diff --git a/files/routes/search.py b/files/routes/search.py index 1816c5aba..9e05b9efd 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -127,7 +127,7 @@ def searchlisting(criteria, v=None, page=1, t="None", sort="top", b=None): 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))