make spicyness of hot algo configurable through .env

This commit is contained in:
rimu 2024-04-15 12:08:04 +12:00
parent a9f4fff576
commit b193f71527
3 changed files with 14 additions and 10 deletions

View file

@ -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

View file

@ -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,

View file

@ -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