Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

TorrentJSON.ID is uint now, fix weird page sorting (#769)

* TorrentJSON.ID is uint now, fix weird page sorting

The bug was that ES would sort by ID in a weird manner because the id
was a string. The id is now a uint.

* Resolved the conflict for future merging
Cette révision appartient à :
tomleb 2017-05-26 21:54:41 -04:00 révisé par ewhal
Parent 113f81b9cc
révision d6c50f5640
7 fichiers modifiés avec 11 ajouts et 13 suppressions

Voir le fichier

@ -165,7 +165,7 @@ func (p *TorrentParam) Find(client *elastic.Client) (int64, []model.Torrent, err
// INFO We are not using Hits.Id because the id in the index might not
// correspond to the id in the database later on.
type TId struct {
Id string
Id uint
}
var tid TId
var torrents []model.Torrent
@ -175,11 +175,11 @@ func (p *TorrentParam) Find(client *elastic.Client) (int64, []model.Torrent, err
// Building a string of the form {id1,id2,id3}
source, _ := hits[0].Source.MarshalJSON()
json.Unmarshal(source, &tid)
idsToString := "{" + tid.Id
idsToString := "{" + strconv.FormatUint(uint64(tid.Id), 10)
for _, t := range hits[1:] {
source, _ = t.Source.MarshalJSON()
json.Unmarshal(source, &tid)
idsToString += "," + tid.Id
idsToString += "," + strconv.FormatUint(uint64(tid.Id), 10)
}
idsToString += "}"
db.ORM.Raw("SELECT * FROM " + config.TorrentsTableName +

Voir le fichier

@ -24,8 +24,7 @@ mappings:
properties:
# TODO Consistent ID's type in TorrentJSON
id:
type: text
fielddata: true # Use to sort by id because it is currently a text field
type: long
name:
type: text
analyzer: nyaapantsu_analyzer

Voir le fichier

@ -32,9 +32,8 @@ fetches = cur.fetchmany(CHUNK_SIZE)
while fetches:
actions = list()
for torrent_id, torrent_name, category, sub_category, status, torrent_hash, date, uploader, downloads, filesize, seeders, leechers, completed in fetches:
# TODO Consistent ID representation on the codebase
doc = {
'id': str(torrent_id),
'id': torrent_id,
'name': torrent_name.decode('utf-8'),
'category': str(category),
'sub_category': str(sub_category),

Voir le fichier

@ -126,7 +126,7 @@ func (t Torrent) AddToESIndex(client *elastic.Client) error {
_, err := client.Index().
Index(config.DefaultElasticsearchIndex).
Type(config.DefaultElasticsearchType).
Id(torrentJSON.ID).
Id(strconv.FormatUint(uint64(torrentJSON.ID), 10)).
BodyJson(torrentJSON).
Refresh("true").
Do(ctx)
@ -203,7 +203,7 @@ type FileJSON struct {
// TorrentJSON for torrent model in json for api
type TorrentJSON struct {
ID string `json:"id"`
ID uint `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
Hash string `json:"hash"`
@ -281,7 +281,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash)
}
res := TorrentJSON{
ID: strconv.FormatUint(uint64(t.ID), 10),
ID: t.ID,
Name: t.Name,
Status: t.Status,
Hash: t.Hash,

Voir le fichier

@ -74,7 +74,7 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
for i, torrent := range torrents {
torrentJSON := torrent.ToJSON()
feed.Items[i] = &feeds.Item{
ID: "https://" + config.WebAddress + "/view/" + torrentJSON.ID,
ID: "https://" + config.WebAddress + "/view/" + strconv.FormatUint(uint64(torrentJSON.ID), 10),
Title: torrent.Name,
Link: &feeds.Link{Href: string(torrentJSON.Magnet)},
Description: string(torrentJSON.Description),

Voir le fichier

@ -27,7 +27,7 @@
</a>
</td>
<td class="tr-name">
<a href="{{genRoute "view_torrent" "id" .ID }}">
<a href="{{genRoute "view_torrent" "id" ( print .ID ) }}">
{{.Name}}
</a>
</td>

Voir le fichier

@ -52,7 +52,7 @@ Your browser does not support the audio element.
</a>
</td>
<td class="tr-name home-td">
<a href="{{genRoute "view_torrent" "id" .ID }}">
<a href="{{genRoute "view_torrent" "id" ( print .ID ) }}">
{{.Name}}
</a>
</td>