Fix NULL problems when sorting by size, fixes #151
Cette révision appartient à :
Parent
004e141c32
révision
ac33a734fd
1 fichiers modifiés avec 9 ajouts et 3 suppressions
|
@ -56,7 +56,13 @@ func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs
|
|||
var torrents []model.Torrents
|
||||
var dbQuery *gorm.DB
|
||||
var count int
|
||||
conditions := "torrent_hash is not null" //filter out broken entries
|
||||
conditions := "torrent_hash IS NOT NULL" // filter out broken entries
|
||||
if strings.HasPrefix(orderBy, "filesize") {
|
||||
// torrents w/ NULL filesize fuck up the sorting on postgres
|
||||
// TODO: fix this properly
|
||||
conditions += " AND filesize IS NOT NULL"
|
||||
}
|
||||
|
||||
var params []interface{}
|
||||
if parameters != nil { // if there is where parameters
|
||||
conditions += " AND " + parameters.Conditions
|
||||
|
@ -65,9 +71,9 @@ func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs
|
|||
db.ORM.Model(&torrents).Where(conditions, params...).Count(&count)
|
||||
dbQuery = db.ORM.Model(&torrents).Where(conditions, params...)
|
||||
|
||||
if orderBy == "" {
|
||||
if orderBy == "" { // default OrderBy
|
||||
orderBy = "torrent_id DESC"
|
||||
} // Default OrderBy
|
||||
}
|
||||
if limit != 0 || offset != 0 { // if limits provided
|
||||
dbQuery = dbQuery.Limit(limit).Offset(offset)
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket