Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Don't look for old comments on new torrents

Cette révision appartient à :
sfan5 2017-05-08 23:40:54 +02:00
Parent ffc3acfc25
révision 975ce5e6d4
2 fichiers modifiés avec 15 ajouts et 3 suppressions

Voir le fichier

@ -10,6 +10,11 @@ import (
"os" "os"
) )
const (
// Highest torrent ID that was copied from nyaa
LastOldTorrentId = 923000
)
type Config struct { type Config struct {
Host string `json: "host"` Host string `json: "host"`
Port int `json: "port"` Port int `json: "port"`

Voir le fichier

@ -44,10 +44,17 @@ func GetFeeds() []model.Feed {
func GetTorrentById(id string) (model.Torrents, error) { func GetTorrentById(id string) (model.Torrents, error) {
var torrent model.Torrents var torrent model.Torrents
id_int, err := strconv.Atoi(id)
if err != nil {
return torrent, err
}
if db.ORM.Where("torrent_id = ?", id). tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments")
Preload("Comments").Preload("OldComments"). if id_int <= config.LastOldTorrentId {
Find(&torrent).RecordNotFound() { // 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.") return torrent, errors.New("Article is not found.")
} }
// .Preload("Comments.User") doesn't work // .Preload("Comments.User") doesn't work