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) SubmitField, TextAreaField)
from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional, Regexp, from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional, Regexp,
StopValidation, ValidationError) StopValidation, ValidationError)
from wtforms.widgets import Select as SelectWidget # For DisabledSelectField
from wtforms.widgets import HTMLString # For DisabledSelectField from wtforms.widgets import HTMLString # For DisabledSelectField
from wtforms.widgets import Select as SelectWidget # For DisabledSelectField
from wtforms.widgets import html_params from wtforms.widgets import html_params
import dns.exception import dns.exception

View File

@ -205,10 +205,8 @@ class TorrentBase(DeclarativeHelperBase):
@classmethod @classmethod
def update_comment_count_db(cls, torrent_id): def update_comment_count_db(cls, torrent_id):
comment_count = db.session.query(func.count(Comment.id)).filter_by( cls.query.filter_by(id=torrent_id).update({'comment_count': db.session.query(
torrent_id=torrent_id).first()[0] func.count(Comment.id)).filter_by(torrent_id=torrent_id).as_scalar()}, False)
db.session.query(cls).filter_by(id=torrent_id).update({'comment_count': comment_count})
return comment_count
@property @property
def created_utc_timestamp(self): def created_utc_timestamp(self):