From 975ce5e6d42ecd0606b90240a4c514847c1426e5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 8 May 2017 23:40:54 +0200 Subject: [PATCH] Don't look for old comments on new torrents --- config/config.go | 5 +++++ service/torrent/torrent.go | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 56fe4699..6627fe5e 100644 --- a/config/config.go +++ b/config/config.go @@ -10,6 +10,11 @@ import ( "os" ) +const ( + // Highest torrent ID that was copied from nyaa + LastOldTorrentId = 923000 +) + type Config struct { Host string `json: "host"` Port int `json: "port"` diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index 69517a4b..d880478c 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -44,10 +44,17 @@ func GetFeeds() []model.Feed { func GetTorrentById(id string) (model.Torrents, error) { var torrent model.Torrents + id_int, err := strconv.Atoi(id) + if err != nil { + return torrent, err + } - if db.ORM.Where("torrent_id = ?", id). - Preload("Comments").Preload("OldComments"). - Find(&torrent).RecordNotFound() { + tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments") + if id_int <= config.LastOldTorrentId { + // only preload old comments if they could actually exist + tmp = tmp.Preload("OldComments") + } + if tmp.Find(&torrent).RecordNotFound() { return torrent, errors.New("Article is not found.") } // .Preload("Comments.User") doesn't work