From 9cdfc00762a96993bd4c558ef101b042423e947c Mon Sep 17 00:00:00 2001 From: akuma06 Date: Wed, 17 May 2017 00:05:16 +0200 Subject: [PATCH] Number of comments Issue #553 --- model/torrent.go | 4 ++++ service/torrent/torrent.go | 2 +- templates/home.html | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/model/torrent.go b/model/torrent.go index 8af3e91d..b7669e53 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -132,7 +132,11 @@ func (t *Torrent) ToJSON() TorrentJSON { commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, Content: template.HTML(c.Content), Date: c.Date.UTC()}) } for _, c := range t.Comments { + if (c.User != nil) { commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC()}) + } else { + commentsJSON = append(commentsJSON, CommentJSON{}) + } } fileListJSON := make([]FileJSON, 0, len(t.FileList)) for _, f := range t.FileList { diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index b6bb2bd8..dac2f303 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -146,7 +146,7 @@ func getTorrentsOrderBy(parameters *serviceBase.WhereParams, orderBy string, lim if limit != 0 || offset != 0 { // if limits provided dbQuery = dbQuery + " LIMIT " + strconv.Itoa(limit) + " OFFSET " + strconv.Itoa(offset) } - err = db.ORM.Raw(dbQuery, params...).Find(&torrents).Error + err = db.ORM.Preload("Comments").Raw(dbQuery, params...).Find(&torrents).Error return } diff --git a/templates/home.html b/templates/home.html index 81f16419..ad65085a 100644 --- a/templates/home.html +++ b/templates/home.html @@ -44,6 +44,7 @@ {{.Name}} + {{.Seeders}} {{.Leechers}}