diff --git a/files/routes/comments.py b/files/routes/comments.py index bcde78894..09f3586c7 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -74,103 +74,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): else: defaultsortingcomments = "top" sort=request.args.get("sort", defaultsortingcomments) - # children comments - - current_ids = [comment.id] - - for i in range(200 - context): - if v: - votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() - - blocking = v.blocking.subquery() - - blocked = v.blocked.subquery() - - comments = g.db.query( - Comment, - votes.c.vote_type, - blocking.c.id, - blocked.c.id, - ) - if v.admin_level >=4: - comments=comments.options(joinedload(Comment.oauth_app)) - - comments=comments.filter( - Comment.parent_comment_id.in_(current_ids) - ).join( - votes, - votes.c.comment_id == Comment.id, - isouter=True - ).join( - blocking, - blocking.c.target_id == Comment.author_id, - isouter=True - ).join( - blocked, - blocked.c.user_id == Comment.author_id, - isouter=True - ) - - if comments.count() == 0: break - - if sort == "top": - comments = sorted(comments.all(), key=lambda x: x[0].score, reverse=True) - elif sort == "bottom": - comments = sorted(comments.all(), key=lambda x: x[0].score) - elif sort == "new": - comments = comments.order_by(Comment.created_utc.desc()).all() - elif sort == "old": - comments = comments.order_by(Comment.created_utc.asc()).all() - elif sort == "controversial": - comments = sorted(comments.all(), key=lambda x: x[0].score_disputed, reverse=True) - elif sort == "random": - c = comments.all() - comments = random.sample(c, k=len(c)) - else: - abort(422) - - output = [] - for c in comments: - comment = c[0] - if comment.author and comment.author.shadowbanned and not (v and v.id == comment.author_id): continue - comment._voted = c[1] or 0 - comment._is_blocking = c[2] or 0 - comment._is_blocked = c[3] or 0 - output.append(comment) - else: - - comments = g.db.query( - Comment - ).filter( - Comment.parent_comment_id.in_(current_ids) - ) - - if comments.count() == 0: break - - if sort == "top": - output = sorted(comments.all(), key=lambda x: x.score, reverse=True) - elif sort == "bottom": - output = sorted(comments.all(), key=lambda x: x.score) - elif sort == "new": - output = comments.order_by(Comment.created_utc.desc()).all() - elif sort == "old": - output = comments.order_by(Comment.created_utc.asc()).all() - elif sort == "controversial": - output = sorted(comments.all(), key=lambda x: x.score_disputed, reverse=True) - elif sort == "random": - c = comments.all() - output = random.sample(c, k=len(c)) - else: - abort(422) - - - post._preloaded_comments += output - - current_ids = [x.id for x in output] - - - post.tree_comments() - post.replies=[top_comment] if request.headers.get("Authorization"): return top_comment.json