Added unique identifier + pprof
Unique identifier for torrent params with p.Identifier() Added pprof support
Cette révision appartient à :
Parent
c8272b180b
révision
2c0293470a
2
main.go
2
main.go
|
@ -9,6 +9,8 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/controllers"
|
||||
"github.com/NyaaPantsu/nyaa/models"
|
||||
|
|
|
@ -84,6 +84,7 @@ func byQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted
|
|||
torrentParam.FromRequest(c)
|
||||
torrentParam.Offset = uint32(pagenum)
|
||||
torrentParam.Hidden = hidden
|
||||
torrentParam.Full = withUser
|
||||
totalHits, torrents, err := torrentParam.Find(models.ElasticSearchClient)
|
||||
// Convert back to non-json torrents
|
||||
return torrentParam, torrents, int(totalHits), err
|
||||
|
|
|
@ -9,15 +9,17 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
catUtil "github.com/NyaaPantsu/nyaa/utils/categories"
|
||||
)
|
||||
|
||||
const (
|
||||
ShowAll Status = 0
|
||||
FilterRemakes = 2
|
||||
Trusted = 3
|
||||
APlus = 4
|
||||
ShowAll Status = 0
|
||||
FilterRemakes = 2
|
||||
Trusted = 3
|
||||
APlus = 4
|
||||
)
|
||||
|
||||
type Status uint8
|
||||
|
@ -31,7 +33,6 @@ type Categories []*Category
|
|||
|
||||
// TorrentParam defines all parameters that can be provided when searching for a torrent
|
||||
type TorrentParam struct {
|
||||
All bool // True means ignore everything but Max and Offset
|
||||
Full bool // True means load all members
|
||||
Order bool // True means ascending
|
||||
Hidden bool // True means filter hidden torrents
|
||||
|
@ -46,13 +47,16 @@ type TorrentParam struct {
|
|||
FromDate DateFilter
|
||||
ToDate DateFilter
|
||||
NotNull string // csv
|
||||
Null string // csv
|
||||
NameLike string // csv
|
||||
Language string
|
||||
MinSize SizeBytes
|
||||
MaxSize SizeBytes
|
||||
}
|
||||
|
||||
func (p *TorrentParam) Identifier() string {
|
||||
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%v%p%p%p", p.NameLike, p.NotNull, p.Language, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, p.FromDate, p.ToDate, p.UserID, p.TorrentID, p.Category, p.Full, p.Order, p.Hidden)
|
||||
}
|
||||
|
||||
func (st *Status) ToString() string {
|
||||
switch *st {
|
||||
case FilterRemakes:
|
||||
|
@ -78,7 +82,6 @@ func (st *Status) Parse(s string) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const (
|
||||
ID SortMode = iota
|
||||
Name
|
||||
|
@ -159,7 +162,6 @@ func (s *SortMode) ToDBField() string {
|
|||
return config.Conf.Torrents.Order
|
||||
}
|
||||
|
||||
|
||||
func (c Category) String() (s string) {
|
||||
if c.Main != 0 {
|
||||
s += strconv.Itoa(int(c.Main))
|
||||
|
@ -214,7 +216,6 @@ func ParseCategories(s string) []*Category {
|
|||
return Categories{}
|
||||
}
|
||||
|
||||
|
||||
func (sz *SizeBytes) Parse(s string, sizeType string) bool {
|
||||
if s == "" {
|
||||
*sz = 0
|
||||
|
@ -240,7 +241,6 @@ func (sz *SizeBytes) Parse(s string, sizeType string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
|
||||
func (d *DateFilter) Parse(s string, dateType string) bool {
|
||||
if s == "" {
|
||||
*d = ""
|
||||
|
@ -261,4 +261,3 @@ func (d *DateFilter) Parse(s string, dateType string) bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -78,10 +78,6 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
|||
p.NameLike = nameLike
|
||||
p.Max = uint32(max)
|
||||
p.UserID = uint32(userID)
|
||||
// TODO Use All
|
||||
p.All = false
|
||||
// TODO Use Full
|
||||
p.Full = false
|
||||
p.Order = ascending
|
||||
p.Status = status
|
||||
p.Sort = sortMode
|
||||
|
@ -101,7 +97,7 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
|||
// ToFilterQuery : Builds a query string with for es query string query defined here
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
|
||||
func (p *TorrentParam) ToFilterQuery() string {
|
||||
// Don't set sub category unless main category is set
|
||||
// Don'p set sub category unless main category is set
|
||||
query := ""
|
||||
if len(p.Category) > 0 {
|
||||
conditionsOr := make([]string, len(p.Category))
|
||||
|
@ -190,7 +186,7 @@ func (p *TorrentParam) Find(client *elastic.Client) (int64, []models.Torrent, er
|
|||
From(int((p.Offset-1)*p.Max)).
|
||||
Size(int(p.Max)).
|
||||
Sort(p.Sort.ToESField(), p.Order).
|
||||
Sort("_score", false) // Don't put _score before the field sort, it messes with the sorting
|
||||
Sort("_score", false) // Don'p put _score before the field sort, it messes with the sorting
|
||||
|
||||
filterQueryString := p.ToFilterQuery()
|
||||
if filterQueryString != "" {
|
||||
|
@ -240,7 +236,6 @@ func (p *TorrentParam) Clone() TorrentParam {
|
|||
FromDate: p.FromDate,
|
||||
ToDate: p.ToDate,
|
||||
NotNull: p.NotNull,
|
||||
Null: p.Null,
|
||||
NameLike: p.NameLike,
|
||||
Language: p.Language,
|
||||
MinSize: p.MinSize,
|
||||
|
|
Référencer dans un nouveau ticket