From b930997c680023009fe2da61caaad3d52318a3d4 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 14 May 2017 17:27:18 +0200 Subject: [PATCH] Make sorting by date date work nicely --- service/torrent/torrent.go | 4 ---- util/search/search.go | 13 ++++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index cadfff5f..d6d7cb0a 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -112,10 +112,6 @@ func getTorrentsOrderBy(parameters *serviceBase.WhereParams, orderBy string, lim ) { var conditionArray []string conditionArray = append(conditionArray, "deleted_at IS NULL") - if strings.HasPrefix(orderBy, "filesize") { - // torrents w/ NULL filesize fuck up the sorting on Postgres - conditionArray = append(conditionArray, "filesize IS NOT NULL") - } var params []interface{} if parameters != nil { // if there is where parameters if len(parameters.Conditions) > 0 { diff --git a/util/search/search.go b/util/search/search.go index f287ef43..3d760874 100644 --- a/util/search/search.go +++ b/util/search/search.go @@ -106,6 +106,7 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool) ( case "2": search.Sort = common.Date orderBy += "date" + search.NotNull = "date IS NOT NULL" break case "3": search.Sort = common.Downloads @@ -114,21 +115,23 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool) ( case "4": search.Sort = common.Size orderBy += "filesize" + // avoid sorting completely breaking on postgres + search.NotNull = "filesize IS NOT NULL" break case "5": search.Sort = common.Seeders orderBy += "seeders" - search.NotNull += "seeders IS NOT NULL " + search.NotNull = "seeders IS NOT NULL" break case "6": search.Sort = common.Leechers orderBy += "leechers" - search.NotNull += "leechers IS NOT NULL " + search.NotNull = "leechers IS NOT NULL" break case "7": search.Sort = common.Completed orderBy += "completed" - search.NotNull += "completed IS NOT NULL " + search.NotNull = "completed IS NOT NULL" break default: search.Sort = common.ID @@ -173,10 +176,6 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool) ( conditions = append(conditions, search.NotNull) } - if len(search.NotNull) > 0 { - conditions = append(conditions, search.NotNull) - } - searchQuerySplit := strings.Fields(search.Query) for _, word := range searchQuerySplit { firstRune, _ := utf8.DecodeRuneInString(word)