From b193f715270949f707ac2f116b9e3539288fd500 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:08:04 +1200 Subject: [PATCH] make spicyness of hot algo configurable through .env --- app/activitypub/util.py | 10 +++++----- app/post/routes.py | 10 +++++----- config.py | 4 ++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index fd86d652..1a463a79 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1039,9 +1039,9 @@ def downvote_post(post, user): post.down_votes += 1 # Make 'hot' sort more spicy by amplifying the effect of early downvotes if post.up_votes + post.down_votes <= 30: - post.score -= 5.0 + post.score -= current_app.config['SPICY_UNDER_30'] elif post.up_votes + post.down_votes <= 60: - post.score -= 2.0 + post.score -= current_app.config['SPICY_UNDER_60'] else: post.score -= 1.0 vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, @@ -1148,11 +1148,11 @@ def upvote_post(post, user): # 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 + spicy_effect = effect * current_app.config['SPICY_UNDER_10'] elif post.up_votes + post.down_votes <= 30: - spicy_effect = effect * 5 + spicy_effect = effect * current_app.config['SPICY_UNDER_30'] elif post.up_votes + post.down_votes <= 60: - spicy_effect = effect * 2 + spicy_effect = effect * current_app.config['SPICY_UNDER_60'] existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first() if not existing_vote: post.up_votes += 1 diff --git a/app/post/routes.py b/app/post/routes.py index f80ab8b3..9a820eab 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -305,20 +305,20 @@ def post_vote(post_id: int, vote_direction): post.up_votes += 1 # Make 'hot' sort more spicy by amplifying the effect of early upvotes if post.up_votes + post.down_votes <= 10: - post.score += 10 + post.score += current_app.config['SPICY_UNDER_10'] elif post.up_votes + post.down_votes <= 30: - post.score += 5 + post.score += current_app.config['SPICY_UNDER_30'] elif post.up_votes + post.down_votes <= 60: - post.score += 2 + post.score += current_app.config['SPICY_UNDER_60'] else: post.score += 1 else: effect = -1 post.down_votes += 1 if post.up_votes + post.down_votes <= 30: - post.score -= 5 + post.score -= current_app.config['SPICY_UNDER_30'] elif post.up_votes + post.down_votes <= 60: - post.score -= 2 + post.score -= current_app.config['SPICY_UNDER_60'] else: post.score -= 1 vote = PostVote(user_id=current_user.id, post_id=post.id, author_id=post.author.id, diff --git a/config.py b/config.py index 7dbe2cc4..67421320 100644 --- a/config.py +++ b/config.py @@ -49,3 +49,7 @@ class Config(object): CLOUDFLARE_API_TOKEN = os.environ.get('CLOUDFLARE_API_TOKEN') or '' CLOUDFLARE_ZONE_ID = os.environ.get('CLOUDFLARE_ZONE_ID') or '' + + SPICY_UNDER_10 = int(os.environ.get('SPICY_UNDER_10')) or 1 + SPICY_UNDER_30 = int(os.environ.get('SPICY_UNDER_30')) or 1 + SPICY_UNDER_60 = int(os.environ.get('SPICY_UNDER_60')) or 1