From 75f52fbd5985d5096a85ddc15954752887bbc4a8 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Thu, 23 May 2024 15:25:45 +1200 Subject: [PATCH] remove avg comment length experiment --- app/activitypub/util.py | 2 -- app/models.py | 15 --------------- app/post/routes.py | 4 ---- app/templates/post/post.html | 3 --- app/templates/user/edit_settings.html | 1 - app/user/forms.py | 1 - app/user/routes.py | 2 -- 7 files changed, 28 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index bf1d191c..710fe99b 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1426,8 +1426,6 @@ def create_post_reply(activity_log: ActivityPubLog, community: Community, in_rep post_reply.ranking = confidence(post_reply.up_votes, post_reply.down_votes) db.session.commit() - user.recalculate_avg_comment_length() - # send notification to the post/comment being replied to if parent_comment_id: notify_about_post_reply(parent_comment, post_reply) diff --git a/app/models.py b/app/models.py index 8eb8e12e..942fab42 100644 --- a/app/models.py +++ b/app/models.py @@ -616,8 +616,6 @@ class User(UserMixin, db.Model): markdown_editor = db.Column(db.Boolean, default=False) interface_language = db.Column(db.String(10)) # a locale that the translation system understands e.g. 'en' or 'en-us'. If empty, use browser default language_id = db.Column(db.Integer, db.ForeignKey('language.id')) # the default choice in the language dropdown when composing posts & comments - average_comment_length = db.Column(db.Integer) - comment_length_warning = db.Column(db.Integer, default=21) avatar = db.relationship('File', lazy='joined', foreign_keys=[avatar_id], single_parent=True, cascade="all, delete-orphan") cover = db.relationship('File', lazy='joined', foreign_keys=[cover_id], single_parent=True, cascade="all, delete-orphan") @@ -811,19 +809,6 @@ class User(UserMixin, db.Model): else: self.attitude = (total_upvotes - total_downvotes) / (total_upvotes + total_downvotes) - def recalculate_avg_comment_length(self): - replies = db.session.execute(text('SELECT body, body_html FROM "post_reply" WHERE user_id = :user_id ORDER BY created_at DESC LIMIT 30'), - {'user_id': self.id}).all() - lengths = [] - for reply in replies: - if reply.body.strip() != '': - lengths.append(len(reply.body.strip())) - else: - soup = BeautifulSoup(reply.body_html, 'html.parser') - lengths.append(len(soup.get_text())) - if len(lengths) > 5: - self.average_comment_length = math.ceil(sum(lengths) / len(lengths)) - def subscribed(self, community_id: int) -> int: if community_id is None: return False diff --git a/app/post/routes.py b/app/post/routes.py index 5ea82b2f..8f9c3fb1 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -111,8 +111,6 @@ def show_post(post_id: int): db.session.add(reply) db.session.commit() - current_user.recalculate_avg_comment_length() - notify_about_post_reply(None, reply) # Subscribe to own comment @@ -673,8 +671,6 @@ def add_reply(post_id: int, comment_id: int): db.session.add(reply) db.session.commit() - current_user.recalculate_avg_comment_length() - # Notify subscribers notify_about_post_reply(in_reply_to, reply) diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 65bbb77d..2f8c29ba 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -100,9 +100,6 @@ {% elif comment['comment'].author.reputation < 0 %} {% endif %} - {% if current_user.is_authenticated and current_user.comment_length_warning and comment['comment'].author.average_comment_length and comment['comment'].author.average_comment_length <= current_user.comment_length_warning %} - - {% endif %} {% endif %} {% if comment['comment'].author.id == post.author.id %}[OP]{% endif %} {{ moment(comment['comment'].posted_at).fromNow(refresh=True) }}{% if comment['comment'].edited_at %}, edited {{ moment(comment['comment'].edited_at).fromNow(refresh=True) }} {% endif %} diff --git a/app/templates/user/edit_settings.html b/app/templates/user/edit_settings.html index 2a60ba83..e3350688 100644 --- a/app/templates/user/edit_settings.html +++ b/app/templates/user/edit_settings.html @@ -35,7 +35,6 @@ {{ render_field(form.markdown_editor) }} {{ render_field(form.default_sort) }} {{ render_field(form.theme) }} - {{ render_field(form.comment_length_warning) }} {{ _('Accounts which usually post comments shorter than this will have a warning. Set to 0 to disable warning.') }}