1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:19:59 +00:00

improve update_comment_count_db

This commit is contained in:
nyaadev 2019-07-09 19:28:48 +02:00
parent 93dffcd663
commit 8b809de8a2
2 changed files with 3 additions and 5 deletions

View file

@ -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

View file

@ -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):