fix controversial sorting, give priority to new posts

remotes/1693045480750635534/spooky-22
Aevann1 2022-06-22 22:30:45 +02:00
parent cc3ddf3c8b
commit 152d39ce6c
2 changed files with 11 additions and 14 deletions

View File

@ -18,17 +18,16 @@ from math import floor
def sort_comments(sort, comments):
if sort == 'new':
order = Comment.id.desc()
return comments.order_by(Comment.id.desc())
elif sort == 'old':
order = Comment.id
return comments.order_by(Comment.id)
elif sort == 'controversial':
order = (Comment.upvotes+1)/(Comment.downvotes+1) + (Comment.downvotes+1)/(Comment.upvotes+1), Comment.downvotes.desc()
return comments.order_by((Comment.upvotes+1)/(Comment.downvotes+1) + (Comment.downvotes+1)/(Comment.upvotes+1), Comment.downvotes.desc(), Comment.id.desc())
elif sort == "bottom":
order = Comment.realupvotes
return comments.order_by(Comment.realupvotes, Comment.id.desc())
else:
order = Comment.realupvotes.desc()
return comments.order_by(Comment.realupvotes.desc(), Comment.id.desc())
return comments.order_by(order)
class Comment(Base):

View File

@ -18,19 +18,17 @@ from .votes import CommentVote
def sort_posts(sort, posts):
if sort == "new":
order = Submission.created_utc.desc()
return posts.order_by(Submission.created_utc.desc())
elif sort == "old":
order = Submission.created_utc
return posts.order_by(Submission.created_utc)
elif sort == "controversial":
order = (Submission.upvotes+1)/(Submission.downvotes+1) + (Submission.downvotes+1)/(Submission.upvotes+1), Submission.downvotes.desc()
return posts.order_by((Submission.upvotes+1)/(Submission.downvotes+1) + (Submission.downvotes+1)/(Submission.upvotes+1), Submission.downvotes.desc(), Submission.created_utc.desc())
elif sort == "bottom":
order = Submission.realupvotes
return posts.order_by(Submission.realupvotes, Submission.created_utc.desc())
elif sort == "comments":
order = Submission.comment_count.desc()
return posts.order_by(Submission.comment_count.desc(), Submission.created_utc.desc())
else:
order = Submission.realupvotes.desc()
return posts.order_by(order)
return posts.order_by(Submission.realupvotes.desc(), Submission.created_utc.desc())
class Submission(Base):
__tablename__ = "submissions"