From f8f55be8b0f8a66317488801680f18be5d601b77 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Fri, 10 Feb 2023 11:54:49 -0800 Subject: [PATCH] constantify render depth limit --- files/classes/submission.py | 4 ++-- files/helpers/const.py | 4 ++++ files/helpers/jinja2.py | 1 + files/routes/posts.py | 2 +- files/templates/comments.html | 22 ++++------------------ files/tests/test_child_comment_counts.py | 7 ++++--- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index ffb4513bf..d081b700e 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -345,8 +345,8 @@ class Submission(Base): url = self.url.replace("old.reddit.com", v.reddit) if '/comments/' in url and "sort=" not in url: - if "?" in url: url += "&context=9" - else: url += "?context=8" + if "?" in url: url += f"&context={RENDER_DEPTH_LIMIT}" + else: url += f"?context={RENDER_DEPTH_LIMIT - 1}" if v.controversial: url += "&sort=controversial" return url elif self.url: diff --git a/files/helpers/const.py b/files/helpers/const.py index 687870682..c6d3d583d 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -55,6 +55,10 @@ ERROR_MESSAGES = { } LOGGEDIN_ACTIVE_TIME = 15 * 60 +RENDER_DEPTH_LIMIT = 9 +''' +The maximum depth at which a comment tree is rendered +''' WERKZEUG_ERROR_DESCRIPTIONS = { 400: "The browser (or proxy) sent a request that this server could not understand.", diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 20174e2c6..8401749b6 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -84,6 +84,7 @@ def inject_constants(): "COLORS":COLORS, "THEMES":THEMES, "PERMS":PERMS, + "RENDER_DEPTH_LIMIT":RENDER_DEPTH_LIMIT, } diff --git a/files/routes/posts.py b/files/routes/posts.py index 08f778214..cf01ee780 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -259,7 +259,7 @@ def morecomments(v, cid): votes.c.vote_type, blocking.c.target_id, blocked.c.target_id, - ).filter(Comment.top_comment_id == tcid, Comment.level > 9).join( + ).filter(Comment.top_comment_id == tcid, Comment.level > RENDER_DEPTH_LIMIT).join( votes, votes.c.comment_id == Comment.id, isouter=True diff --git a/files/templates/comments.html b/files/templates/comments.html index 6ea8d1e93..32cc69fb5 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -72,20 +72,15 @@
- {% if standalone and c.over_18 %}+18 {% endif %} + {% if standalone and c.over_18 %}+18{% endif %} {% if c.is_banned %}removed by @{{c.ban_reason}}{% elif c.deleted_utc %}Deleted by author{% elif c.is_blocking %}You are blocking @{{c.author_name}}{% endif %}
- -
- - - -
+
{% if render_replies %} - {% if level<9 %} + {% if level <= RENDER_DEPTH_LIMIT - 1 %}
{% set standalone=False %} {% for reply in replies %} @@ -541,7 +536,7 @@ {% if render_replies %} - {% if level<9 or request.path == '/notifications' %} + {% if level <= RENDER_DEPTH_LIMIT - 1 or request.path == '/notifications' %}
{% for reply in replies %} {{single_comment(reply, level=level+1)}} @@ -712,15 +707,6 @@
{% endif %} - - - - - - - - -
{% endif %} diff --git a/files/tests/test_child_comment_counts.py b/files/tests/test_child_comment_counts.py index 71980d09a..01f2365fd 100644 --- a/files/tests/test_child_comment_counts.py +++ b/files/tests/test_child_comment_counts.py @@ -1,3 +1,4 @@ +from files.helpers.const import RENDER_DEPTH_LIMIT from . import fixture_accounts from . import fixture_submissions from . import fixture_comments @@ -158,10 +159,10 @@ def test_more_button_label_in_deep_threads(accounts, submissions, comments): # only look every 5 posts to make this test not _too_ unbearably slow view_post_response = alice_client.get(f'/post/{post.id}') assert 200 == view_post_response.status_code - if i <= 8: - assert f'More comments ({i - 8})' not in view_post_response.text + if i <= RENDER_DEPTH_LIMIT - 1: + assert f'More comments ({i - RENDER_DEPTH_LIMIT + 1})' not in view_post_response.text else: - assert f'More comments ({i - 8})' in view_post_response.text + assert f'More comments ({i - RENDER_DEPTH_LIMIT + 1})' in view_post_response.text @util.no_rate_limit def test_bulk_update_descendant_count_quick(accounts, submissions, comments):