From 5bdd160d612c73b8ac94613d6d5db443968b49e7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 8 May 2017 22:46:49 +0200 Subject: [PATCH] Fix absence of pagination on home page --- service/torrent/torrent.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index 6cca1586..69517a4b 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -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