From 8b809de8a27603c4a5c334415c4a6a331b8f033a Mon Sep 17 00:00:00 2001 From: nyaadev Date: Tue, 9 Jul 2019 19:28:48 +0200 Subject: [PATCH] improve update_comment_count_db --- nyaa/forms.py | 2 +- nyaa/models.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/nyaa/forms.py b/nyaa/forms.py index 84334d5..af15003 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 Select as SelectWidget # For DisabledSelectField from wtforms.widgets import HTMLString # For DisabledSelectField +from wtforms.widgets import Select as SelectWidget # For DisabledSelectField from wtforms.widgets import html_params import dns.exception diff --git a/nyaa/models.py b/nyaa/models.py index e4bc387..24a9769 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -205,10 +205,8 @@ class TorrentBase(DeclarativeHelperBase): @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 + cls.query.filter_by(id=torrent_id).update({'comment_count': db.session.query( + func.count(Comment.id)).filter_by(torrent_id=torrent_id).as_scalar()}, False) @property def created_utc_timestamp(self):