Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Forgot Sort field in cache

Cette révision appartient à :
akuma06 2017-07-07 00:18:11 +02:00
Parent bee64decb7
révision 15c4f788be
2 fichiers modifiés avec 12 ajouts et 6 suppressions

Voir le fichier

@ -8,6 +8,8 @@ import (
"time"
"fmt"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/torrents"
@ -92,6 +94,7 @@ func byQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted
return torrentParam, torrentCache.Torrents, torrentCache.Count, nil
}
totalHits, tor, err := torrentParam.Find(models.ElasticSearchClient)
fmt.Println("lol")
cache.C.Set(torrentParam.Identifier(), &structs.TorrentCache{tor, int(totalHits)}, 5*time.Minute)
// Convert back to non-json torrents
return torrentParam, tor, int(totalHits), err
@ -109,6 +112,10 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
search.Hidden = hidden
search.Full = withUser
orderBy := search.Sort.ToDBField()
if search.Sort == structs.Date {
search.NotNull = search.Sort.ToDBField() + " IS NOT NULL"
}
if found, ok := cache.C.Get(search.Identifier()); ok {
torrentCache := found.(*structs.TorrentCache)
tor = torrentCache.Torrents
@ -116,11 +123,6 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
return
}
orderBy := search.Sort.ToDBField()
if search.Sort == structs.Date {
search.NotNull = search.Sort.ToDBField() + " IS NOT NULL"
}
orderBy += " "
switch search.Order {

Voir le fichier

@ -54,7 +54,11 @@ type TorrentParam struct {
}
func (p *TorrentParam) Identifier() string {
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%v%t%t%t", 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)
cats := ""
for _, v := range p.Category {
cats += fmt.Sprintf("%d%d", v.Main, v.Sub)
}
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%s%t%t%t", 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, cats, p.Full, p.Order, p.Hidden)
}
func (st *Status) ToString() string {