diff --git a/nyaa/forms.py b/nyaa/forms.py index 356fc40..84334d5 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -11,8 +11,8 @@ from wtforms import (BooleanField, HiddenField, PasswordField, SelectField, Stri SubmitField, TextAreaField) from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional, Regexp, StopValidation, ValidationError) -from wtforms.widgets import HTMLString # For DisabledSelectField from wtforms.widgets import Select as SelectWidget # For DisabledSelectField +from wtforms.widgets import HTMLString # For DisabledSelectField from wtforms.widgets import html_params import dns.exception @@ -346,6 +346,7 @@ class BanForm(FlaskForm): class NukeForm(FlaskForm): nuke_torrents = SubmitField("\U0001F4A3 Nuke Torrents") + nuke_comments = SubmitField("\U0001F4A3 Nuke Comments") class UploadForm(FlaskForm): diff --git a/nyaa/models.py b/nyaa/models.py index 44697a0..e4bc387 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -199,9 +199,17 @@ class TorrentBase(DeclarativeHelperBase): return '<{0} #{1.id} \'{1.display_name}\' {1.filesize}b>'.format(type(self).__name__, self) def update_comment_count(self): - self.comment_count = Comment.query.filter_by(torrent_id=self.id).count() + self.comment_count = db.session.query(func.count( + Comment.id)).filter_by(torrent_id=self.id).first()[0] return self.comment_count + @classmethod + def update_comment_count_db(cls, torrent_id): + comment_count = db.session.query(func.count(Comment.id)).filter_by( + torrent_id=torrent_id).first()[0] + db.session.query(cls).filter_by(id=torrent_id).update({'comment_count': comment_count}) + return comment_count + @property def created_utc_timestamp(self): ''' Returns a UTC POSIX timestamp, as seconds ''' diff --git a/nyaa/template_utils.py b/nyaa/template_utils.py index ff2904a..5a1473d 100644 --- a/nyaa/template_utils.py +++ b/nyaa/template_utils.py @@ -29,7 +29,7 @@ def create_magnet_from_es_torrent(): flask_url_for = flask.url_for -@functools.lru_cache(maxsize=1024*4) +@functools.lru_cache(maxsize=1024 * 4) def _caching_url_for(endpoint, **values): return flask_url_for(endpoint, **values) diff --git a/nyaa/templates/user.html b/nyaa/templates/user.html index 3becb30..9fbf91e 100644 --- a/nyaa/templates/user.html +++ b/nyaa/templates/user.html @@ -138,6 +138,9 @@