From 9fe2ffd72ee4b6b9756bc0132abbd2d31222d606 Mon Sep 17 00:00:00 2001 From: Michael House Date: Fri, 9 Sep 2022 17:11:12 -0500 Subject: [PATCH] Added comments-per-page config. --- env | 1 + files/__main__.py | 1 + files/routes/posts.py | 14 +++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/env b/env index 84cccec33..0a1e812d5 100644 --- a/env +++ b/env @@ -32,6 +32,7 @@ CF_ZONE=blahblahblah DEBIAN_FRONTEND=noninteractive MENTION_LIMIT=100 MULTIMEDIA_EMBEDDING_ENABLED=False +RESULTS_PER_PAGE_COMMENTS=200 # Profiling system; uncomment to enable # Stores and exposes sensitive data! diff --git a/files/__main__.py b/files/__main__.py index f7a2aa11f..a6f2efb98 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -78,6 +78,7 @@ app.config['SETTINGS'] = {} app.config['SQLALCHEMY_DATABASE_URI'] = app.config['DATABASE_URL'] app.config['MENTION_LIMIT'] = int(environ.get('MENTION_LIMIT', 100)) app.config['MULTIMEDIA_EMBEDDING_ENABLED'] = environ.get('MULTIMEDIA_EMBEDDING_ENABLED', "false").lower() == "true" +app.config['RESULTS_PER_PAGE_COMMENTS'] = int(environ.get('RESULTS_PER_PAGE_COMMENTS',50)) r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) diff --git a/files/routes/posts.py b/files/routes/posts.py index ff362e179..fb5fcf5fc 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -230,7 +230,9 @@ def post_id(pid, anything=None, v=None, sub=None): offset = 0 ids = set() - if post.comment_count > 60 and not request.headers.get("Authorization") and not request.values.get("all"): + limit = app.config['RESULTS_PER_PAGE_COMMENTS'] + + if post.comment_count > limit and not request.headers.get("Authorization") and not request.values.get("all"): comments2 = [] count = 0 if post.created_utc > 1638672040: @@ -238,13 +240,13 @@ def post_id(pid, anything=None, v=None, sub=None): comments2.append(comment) ids.add(comment.id) count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1 - if count > 50: break + if count > limit: break else: for comment in comments: comments2.append(comment) ids.add(comment.id) count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1 - if count > 10: break + if count > limit: break if len(comments) == len(comments2): offset = 0 else: offset = 1 @@ -357,20 +359,22 @@ def viewmore(v, pid, sort, offset): comments = comments.all() comments = comments[offset:] + limit = app.config['RESULTS_PER_PAGE_COMMENTS'] comments2 = [] count = 0 + if post.created_utc > 1638672040: for comment in comments: comments2.append(comment) ids.add(comment.id) count += g.db.query(Comment.id).filter_by(parent_submission=post.id, top_comment_id=comment.id).count() + 1 - if count > 50: break + if count > limit: break else: for comment in comments: comments2.append(comment) ids.add(comment.id) count += g.db.query(Comment.id).filter_by(parent_submission=post.id, parent_comment_id=comment.id).count() + 1 - if count > 10: break + if count > limit: break if len(comments) == len(comments2): offset = 0 else: offset += 1