Fix search Status (#1467)
Should fix #1428 ?s=2 and others. Reason: the sql query wasn't correct when filtering (status >= ? = ?)
Cette révision appartient à :
Parent
406c5c879b
révision
38d3e45ef4
3 fichiers modifiés avec 18 ajouts et 10 suppressions
|
@ -63,16 +63,16 @@ func (st *Status) ToESQuery() string {
|
|||
}
|
||||
|
||||
// ToDBQuery prepare a DB statement for status
|
||||
func (st *Status) ToDBQuery() string {
|
||||
func (st *Status) ToDBQuery() (string, string) {
|
||||
if *st != ShowAll {
|
||||
if *st != FilterRemakes {
|
||||
// Only show torrents with status over the one specified
|
||||
return "status >= " + st.String()
|
||||
return "status >= ?", st.String()
|
||||
}
|
||||
/* From the old nyaa behavior, FilterRemake means everything BUT
|
||||
* remakes
|
||||
*/
|
||||
return "status <> " + st.String()
|
||||
return "status <> ?", st.String()
|
||||
}
|
||||
return ""
|
||||
return "", ""
|
||||
}
|
||||
|
|
|
@ -45,11 +45,19 @@ func TestStatus_ToESQuery(t *testing.T) {
|
|||
func TestStatus_ToDBQuery(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
status := Status(0)
|
||||
assert.Empty(status.ToDBQuery(), "Should be empty")
|
||||
sql, st := status.ToDBQuery()
|
||||
assert.Empty(sql, "Should be empty")
|
||||
assert.Empty(st, "Should be empty")
|
||||
status = Status(3)
|
||||
assert.Equal("status >= 3", status.ToDBQuery(), "Should be equal")
|
||||
sql, st = status.ToDBQuery()
|
||||
assert.Equal("status >= ?", sql, "Should be equal")
|
||||
assert.Equal("3", st, "Should be equal")
|
||||
status = Status(1)
|
||||
assert.Equal("status >= 1", status.ToDBQuery(), "Should be equal")
|
||||
sql, st = status.ToDBQuery()
|
||||
assert.Equal("status >= ?", sql, "Should be equal")
|
||||
assert.Equal("1", st, "Should be equal")
|
||||
status = Status(2)
|
||||
assert.Equal("status <> 2", status.ToDBQuery(), "Should be equal")
|
||||
sql, st = status.ToDBQuery()
|
||||
assert.Equal("status <> ?", sql, "Should be equal")
|
||||
assert.Equal("2", st, "Should be equal")
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query {
|
|||
|
||||
sql, cats := p.Category.ToDBQuery()
|
||||
query.Append(sql, cats...)
|
||||
|
||||
|
||||
if len(p.Languages) > 0 {
|
||||
query.Append("language "+searchOperator, "%"+langsToDBQuery(p.Languages)+"%")
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query {
|
|||
query.Append("date <= ?", p.ToDate.ToDBQuery())
|
||||
}
|
||||
if p.Status != 0 {
|
||||
query.Append(p.Status.ToDBQuery(), strconv.Itoa(int(p.Status)+1))
|
||||
query.Append(p.Status.ToDBQuery())
|
||||
}
|
||||
if len(p.NotNull) > 0 {
|
||||
query.Append(p.NotNull)
|
||||
|
|
Référencer dans un nouveau ticket