From 716f078e81d8de792f82b85c815cfe3c70df9221 Mon Sep 17 00:00:00 2001 From: TLSM Date: Mon, 12 Sep 2022 08:06:24 -0400 Subject: [PATCH] Fix 'hot' sort intermediate value out-of-bounds. Fixes #321. Due to the extremely large quantity of comments on a typical Motte post, 'hot' sorting logic underflowed an intermediate value. Roughly: |(-1 000 000) * (103 [votes] + 1 + 2723 [comments] / 1)| > 2^31 We resolve this by reducing the coefficient from 1e6 to 1e5, which reduces precision of intermediate calculations somewhat, and by dividing #comments by 10 rather than 1, which better matches Motte user behavior regardless: Users comment much more often than vote. This buys us two orders of magnitude more headroom before out-of- bounds. Shouldn't be an issue until the CW thread reaches ~200k comments. --- files/routes/front.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/routes/front.py b/files/routes/front.py index c60d0a987..58dedf2d0 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -340,11 +340,13 @@ def frontlist(v=None, sort='new', page=1, t="all", ids_only=True, ccmode="false" if not (v and v.shadowbanned): posts = posts.join(User, User.id == Submission.author_id).filter(User.shadowbanned == None) - num = 1 - if sort == "hot": ti = int(time.time()) + 3600 - posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/num + (func.length(Submission.body_html)-func.length(func.replace(Submission.body_html,'','')))/4)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc()) + posts = posts.order_by( + -100000 + * (Submission.realupvotes + 1 + Submission.comment_count / 10) + / (func.power((ti - Submission.created_utc) / 1000, 1.23)), + Submission.created_utc.desc()) elif sort == "bump": posts = posts.filter(Submission.comment_count > 1).order_by(Submission.bump_utc.desc(), Submission.created_utc.desc()) elif sort == "new":