diff --git a/nyaa/models.py b/nyaa/models.py index 9e81629..2897319 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -192,7 +192,7 @@ class TorrentBase(DeclarativeHelperBase): @declarative.declared_attr def comments(cls): return db.relationship(cls._flavor_prefix('Comment'), uselist=True, - cascade="all, delete-orphan") + cascade="all, delete-orphan", lazy='noload') def __repr__(self): return '<{0} #{1.id} \'{1.display_name}\' {1.filesize}b>'.format(type(self).__name__, self) @@ -435,7 +435,7 @@ class CommentBase(DeclarativeHelperBase): @declarative.declared_attr def torrent(cls): return db.relationship(cls._flavor_prefix('Torrent'), uselist=False, - back_populates='comments', lazy="joined") + back_populates='comments', lazy="noload") def __repr__(self): return '' % self.id @@ -499,7 +499,7 @@ class User(db.Model): bans = db.relationship('Ban', uselist=True, foreign_keys='Ban.user_id') preferences = db.relationship('UserPreferences', - back_populates='user', uselist=False, lazy='joined') + back_populates='user', uselist=False, lazy='select') def __init__(self, username, email, password): self.username = username diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index 7be7b18..e7cb93e 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -140,7 +140,7 @@

- Comments - {{ comments | length }} + Comments - {{ torrent.comment_count }}

diff --git a/nyaa/views/torrents.py b/nyaa/views/torrents.py index 36cc1a4..5dc9bb8 100644 --- a/nyaa/views/torrents.py +++ b/nyaa/views/torrents.py @@ -21,10 +21,12 @@ def view_torrent(torrent_id): torrent = models.Torrent.by_id(torrent_id) else: torrent = models.Torrent.query \ - .options(joinedload('filelist'), - joinedload('comments')) \ + .options(joinedload('filelist')) \ .filter_by(id=torrent_id) \ .first() + comments = models.Comment.query \ + .filter_by(torrent_id=torrent_id) + if not torrent: flask.abort(404) @@ -71,7 +73,7 @@ def view_torrent(torrent_id): return flask.render_template('view.html', torrent=torrent, files=files, comment_form=comment_form, - comments=torrent.comments, + comments=comments, can_edit=can_edit, report_form=report_form)