Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix absence of pagination on home page

Cette révision appartient à :
sfan5 2017-05-08 22:46:49 +02:00
Parent 61b34c109d
révision 5bdd160d61

Voir le fichier

@ -62,20 +62,22 @@ func GetTorrentById(id string) (model.Torrents, error) {
func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offset int) ([]model.Torrents, int) {
var torrents []model.Torrents
var count int
conditions := "1" // FIXME
var conditionArray []string
if strings.HasPrefix(orderBy, "filesize") {
// torrents w/ NULL filesize fuck up the sorting on postgres
conditions += " AND filesize IS NOT NULL"
conditionArray = append(conditionArray, "filesize IS NOT NULL")
}
var params []interface{}
if parameters != nil { // if there is where parameters
if len(parameters.Conditions) > 0 {
conditions += " AND " + parameters.Conditions
conditionArray = append(conditionArray, parameters.Conditions)
}
params = parameters.Params
}
conditions := strings.Join(conditionArray, " AND ")
db.ORM.Model(&torrents).Where(conditions, params...).Count(&count)
// build custom db query for performance reasons
dbQuery := "SELECT * FROM torrents"
if conditions != "" {
dbQuery = dbQuery + " WHERE " + conditions