From 75c3f7c8be6e0fe5f07046577f2956dd5aedca84 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 14 Apr 2024 07:59:24 +1200 Subject: [PATCH] hot sort - more spicy pls (experiment) --- app/activitypub/util.py | 18 ++++++++++++++++-- app/community/routes.py | 2 +- app/main/routes.py | 2 +- app/post/routes.py | 13 +++++++++++-- app/topic/routes.py | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index f6563c1e..fd86d652 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1037,7 +1037,13 @@ def downvote_post(post, user): if not existing_vote: effect = -1.0 post.down_votes += 1 - post.score -= 1.0 + # Make 'hot' sort more spicy by amplifying the effect of early downvotes + if post.up_votes + post.down_votes <= 30: + post.score -= 5.0 + elif post.up_votes + post.down_votes <= 60: + post.score -= 2.0 + else: + post.score -= 1.0 vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, effect=effect) post.author.reputation += effect @@ -1139,10 +1145,18 @@ def upvote_post(post, user): user.last_seen = utcnow() user.recalculate_attitude() effect = instance_weight(user.ap_domain) + # Make 'hot' sort more spicy by amplifying the effect of early upvotes + spicy_effect = effect + if post.up_votes + post.down_votes <= 10: + spicy_effect = effect * 10 + elif post.up_votes + post.down_votes <= 30: + spicy_effect = effect * 5 + elif post.up_votes + post.down_votes <= 60: + spicy_effect = effect * 2 existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first() if not existing_vote: post.up_votes += 1 - post.score += effect + post.score += spicy_effect vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, effect=effect) if post.community.low_quality and effect > 0: diff --git a/app/community/routes.py b/app/community/routes.py index 96b53bdb..03cbe021 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -184,7 +184,7 @@ def show_community(community: Community): if sort == '' or sort == 'hot': posts = posts.order_by(desc(Post.sticky)).order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': - posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.score)) + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.up_votes - Post.down_votes)) elif sort == 'new': posts = posts.order_by(desc(Post.posted_at)) elif sort == 'active': diff --git a/app/main/routes.py b/app/main/routes.py index 4af5798f..d90f55d3 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -114,7 +114,7 @@ def home_page(type, sort): if sort == 'hot': posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': - posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=1)).order_by(desc(Post.score)) + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=1)).order_by(desc(Post.up_votes - Post.down_votes)) elif sort == 'new': posts = posts.order_by(desc(Post.posted_at)) elif sort == 'active': diff --git a/app/post/routes.py b/app/post/routes.py index c3f72e3d..2f62b4d8 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -303,11 +303,20 @@ def post_vote(post_id: int, vote_direction): if vote_direction == 'upvote': effect = 1 post.up_votes += 1 - post.score += 1 + # Make 'hot' sort more spicy by amplifying the effect of early upvotes + if post.up_votes + post.down_votes <= 10: + post.score += 5 + elif post.up_votes + post.down_votes <= 100: + post.score += 2 + else: + post.score += 1 else: effect = -1 post.down_votes += 1 - post.score -= 1 + if post.up_votes + post.down_votes <= 100: + post.score -= 2 + else: + post.score -= 1 vote = PostVote(user_id=current_user.id, post_id=post.id, author_id=post.author.id, effect=effect) # upvotes do not increase reputation in low quality communities diff --git a/app/topic/routes.py b/app/topic/routes.py index a3a0a9dc..325342d4 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -77,7 +77,7 @@ def show_topic(topic_path): if sort == '' or sort == 'hot': posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at)) elif sort == 'top': - posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.score)) + posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.up_votes - Post.down_votes)) elif sort == 'new': posts = posts.order_by(desc(Post.posted_at)) elif sort == 'active':