From 66ddf6269a1c9b85cec07b530dd2b849d821ddce Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 7 May 2017 13:23:31 -0400 Subject: [PATCH 01/17] don't use type=number --- templates/_captcha.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/_captcha.html b/templates/_captcha.html index 95fadb8e..4e90b98b 100644 --- a/templates/_captcha.html +++ b/templates/_captcha.html @@ -3,6 +3,6 @@ - + {{end}} From 5819c0db48b8b7e882ed586b92994ffd838d7478 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 7 May 2017 13:34:53 -0400 Subject: [PATCH 02/17] filter out more broken entries --- service/torrent/torrent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index 89d4b049..4837f321 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -56,7 +56,7 @@ 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 AND filesize > 0" //filter out broken entries var params []interface{} if parameters != nil { // if there is where parameters conditions += " AND " + parameters.Conditions From 28ef70c960cb2297cec219b36d6918c0eb21fbdf Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 7 May 2017 13:50:55 -0400 Subject: [PATCH 03/17] make rss feeds faster --- router/rssHandler.go | 10 +++++----- router/searchHandler.go | 2 +- service/torrent/torrent.go | 20 ++++++++++++++++++-- util/search/search.go | 21 +++++++++++++++++---- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/router/rssHandler.go b/router/rssHandler.go index 402dafd2..3b2e1cf7 100644 --- a/router/rssHandler.go +++ b/router/rssHandler.go @@ -1,17 +1,17 @@ package router -import( - "time" - "net/http" - "github.com/gorilla/feeds" +import ( "github.com/ewhal/nyaa/config" "github.com/ewhal/nyaa/util/search" + "github.com/gorilla/feeds" + "net/http" "strconv" + "time" ) func RssHandler(w http.ResponseWriter, r *http.Request) { - _, torrents, _ := search.SearchByQuery( r, 1 ) + _, torrents := search.SearchByQueryNoCount(r, 1) created_as_time := time.Now() if len(torrents) > 0 { diff --git a/router/searchHandler.go b/router/searchHandler.go index c44bf29e..b91933a8 100644 --- a/router/searchHandler.go +++ b/router/searchHandler.go @@ -23,7 +23,7 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) { search_param, torrents, nbTorrents := search.SearchByQuery(r, pagenum) - for i, _ := range torrents { + for i := range torrents { res := torrents[i].ToJson() b = append(b, res) } diff --git a/service/torrent/torrent.go b/service/torrent/torrent.go index 4837f321..b461a66b 100644 --- a/service/torrent/torrent.go +++ b/service/torrent/torrent.go @@ -53,6 +53,15 @@ func GetTorrentById(id string) (model.Torrents, error) { } func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offset int) ([]model.Torrents, int) { + return getTorrentsOrderBy(parameters, orderBy, limit, offset, true) +} + +func GetTorrentsOrderByNoCount(parameters *WhereParams, orderBy string, limit int, offset int) (torrents []model.Torrents) { + torrents, _ = getTorrentsOrderBy(parameters, orderBy, limit, offset, false) + return +} + +func getTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offset int, countAll bool) ([]model.Torrents, int) { var torrents []model.Torrents var dbQuery *gorm.DB var count int @@ -62,7 +71,9 @@ func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs conditions += " AND " + parameters.Conditions params = parameters.Params } - db.ORM.Model(&torrents).Where(conditions, params...).Count(&count) + if countAll { + db.ORM.Model(&torrents).Where(conditions, params...).Count(&count) + } dbQuery = db.ORM.Model(&torrents).Where(conditions, params...) if orderBy == "" { @@ -80,7 +91,7 @@ func GetTorrentsOrderBy(parameters *WhereParams, orderBy string, limit int, offs * Get Torrents with where parameters and limits, order by default */ func GetTorrents(parameters WhereParams, limit int, offset int) ([]model.Torrents, int) { - return GetTorrentsOrderBy(¶meters, "", limit, offset) + return getTorrentsOrderBy(¶meters, "", limit, offset, true) } /* Get Torrents with where parameters but no limit and order by default (get all the torrents corresponding in the db) @@ -101,6 +112,11 @@ func GetAllTorrents(limit int, offset int) ([]model.Torrents, int) { return GetTorrentsOrderBy(nil, "", limit, offset) } +func GetAllTorrentsNoCouting(limit int, offset int) (torrents []model.Torrents) { + torrents, _ = getTorrentsOrderBy(nil, "", limit, offset, false) + return +} + func GetAllTorrentsDB() ([]model.Torrents, int) { return GetTorrentsOrderBy(nil, "", 0, 0) } diff --git a/util/search/search.go b/util/search/search.go index f79d3f4d..f0487bed 100644 --- a/util/search/search.go +++ b/util/search/search.go @@ -20,6 +20,16 @@ type SearchParam struct { } func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, int) { + return searchByQuery(r, pagenum, true) + +} + +func SearchByQueryNoCount(r *http.Request, pagenum int) (param SearchParam, torrents []model.Torrents) { + param, torrents, _ = searchByQuery(r, pagenum, false) + return +} + +func searchByQuery(r *http.Request, pagenum int, count bool) (search_param SearchParam, torrents []model.Torrents, n int) { maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")) if errConv != nil { maxPerPage = 50 // default Value maxPerPage @@ -28,7 +38,6 @@ func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, if maxPerPage > 300 { maxPerPage = 300 } - search_param := SearchParam{} search_param.Max = maxPerPage search_param.Query = r.URL.Query().Get("q") search_param.Category = r.URL.Query().Get("c") @@ -71,13 +80,17 @@ func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents, parameters.Params = append(parameters.Params, search_param.Status) } searchQuerySplit := strings.Split(search_param.Query, " ") - for i, _ := range searchQuerySplit { + for i := range searchQuerySplit { conditions = append(conditions, "torrent_name LIKE ?") parameters.Params = append(parameters.Params, "%"+searchQuerySplit[i]+"%") } parameters.Conditions = strings.Join(conditions[:], " AND ") log.Infof("SQL query is :: %s\n", parameters.Conditions) - torrents, n := torrentService.GetTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1)) - return search_param, torrents, n + if count { + torrents, n = torrentService.GetTorrentsOrderBy(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1)) + } else { + torrents = torrentService.GetTorrentsOrderByNoCount(¶meters, order_by, maxPerPage, maxPerPage*(pagenum-1)) + } + return } From a3e0cc0503f0927064502a970f0e106470cfcdd2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 7 May 2017 21:28:35 +0200 Subject: [PATCH 04/17] Fix accidental duplicate css --- public/css/style-night.css | 4 ++-- public/css/style.css | 2 +- templates/index.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/css/style-night.css b/public/css/style-night.css index ec5f2263..580c4280 100644 --- a/public/css/style-night.css +++ b/public/css/style-night.css @@ -2,7 +2,7 @@ .nightswitch { position: fixed; top: 12px; - right: 48px; + right: 12px; } .nightswitch > a > img { width: 24px; @@ -180,4 +180,4 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ .navbar { border-radius: 0px; -} \ No newline at end of file +} diff --git a/public/css/style.css b/public/css/style.css index 7877c119..f522ec6e 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -2,7 +2,7 @@ .nightswitch { position: fixed; top: 12px; - right: 48px; + right: 12px; } .nightswitch > a > img { width: 24px; diff --git a/templates/index.html b/templates/index.html index 112d8143..9b6c3391 100755 --- a/templates/index.html +++ b/templates/index.html @@ -55,7 +55,7 @@ {{block "search_button" .}}{{end}} -
+
From d099a77c88e2843da7b387f37e1bdc3a048e780b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 7 May 2017 21:36:59 +0200 Subject: [PATCH 05/17] Inline style-switching JS into --- public/js/main.js | 6 ------ templates/index.html | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 657a4909..4d5b47d7 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,10 +1,4 @@ // Night mode -var night = localStorage.getItem("night"); -if (night == "true") { - $("#style")[0].href = "/css/style-night.css"; - $("#nighticon")[0].src = "/img/sun.png"; -} - function toggleNightMode() { var night = localStorage.getItem("night"); if(night == "true") { diff --git a/templates/index.html b/templates/index.html index 9b6c3391..eef8f1d1 100755 --- a/templates/index.html +++ b/templates/index.html @@ -27,6 +27,15 @@ +