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 à :
Parent
113f81b9cc
révision
d6c50f5640
7 fichiers modifiés avec 11 ajouts et 13 suppressions
|
@ -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
|
// INFO We are not using Hits.Id because the id in the index might not
|
||||||
// correspond to the id in the database later on.
|
// correspond to the id in the database later on.
|
||||||
type TId struct {
|
type TId struct {
|
||||||
Id string
|
Id uint
|
||||||
}
|
}
|
||||||
var tid TId
|
var tid TId
|
||||||
var torrents []model.Torrent
|
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}
|
// Building a string of the form {id1,id2,id3}
|
||||||
source, _ := hits[0].Source.MarshalJSON()
|
source, _ := hits[0].Source.MarshalJSON()
|
||||||
json.Unmarshal(source, &tid)
|
json.Unmarshal(source, &tid)
|
||||||
idsToString := "{" + tid.Id
|
idsToString := "{" + strconv.FormatUint(uint64(tid.Id), 10)
|
||||||
for _, t := range hits[1:] {
|
for _, t := range hits[1:] {
|
||||||
source, _ = t.Source.MarshalJSON()
|
source, _ = t.Source.MarshalJSON()
|
||||||
json.Unmarshal(source, &tid)
|
json.Unmarshal(source, &tid)
|
||||||
idsToString += "," + tid.Id
|
idsToString += "," + strconv.FormatUint(uint64(tid.Id), 10)
|
||||||
}
|
}
|
||||||
idsToString += "}"
|
idsToString += "}"
|
||||||
db.ORM.Raw("SELECT * FROM " + config.TorrentsTableName +
|
db.ORM.Raw("SELECT * FROM " + config.TorrentsTableName +
|
||||||
|
|
|
@ -24,8 +24,7 @@ mappings:
|
||||||
properties:
|
properties:
|
||||||
# TODO Consistent ID's type in TorrentJSON
|
# TODO Consistent ID's type in TorrentJSON
|
||||||
id:
|
id:
|
||||||
type: text
|
type: long
|
||||||
fielddata: true # Use to sort by id because it is currently a text field
|
|
||||||
name:
|
name:
|
||||||
type: text
|
type: text
|
||||||
analyzer: nyaapantsu_analyzer
|
analyzer: nyaapantsu_analyzer
|
||||||
|
|
|
@ -32,9 +32,8 @@ fetches = cur.fetchmany(CHUNK_SIZE)
|
||||||
while fetches:
|
while fetches:
|
||||||
actions = list()
|
actions = list()
|
||||||
for torrent_id, torrent_name, category, sub_category, status, torrent_hash, date, uploader, downloads, filesize, seeders, leechers, completed in fetches:
|
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 = {
|
doc = {
|
||||||
'id': str(torrent_id),
|
'id': torrent_id,
|
||||||
'name': torrent_name.decode('utf-8'),
|
'name': torrent_name.decode('utf-8'),
|
||||||
'category': str(category),
|
'category': str(category),
|
||||||
'sub_category': str(sub_category),
|
'sub_category': str(sub_category),
|
||||||
|
|
|
@ -126,7 +126,7 @@ func (t Torrent) AddToESIndex(client *elastic.Client) error {
|
||||||
_, err := client.Index().
|
_, err := client.Index().
|
||||||
Index(config.DefaultElasticsearchIndex).
|
Index(config.DefaultElasticsearchIndex).
|
||||||
Type(config.DefaultElasticsearchType).
|
Type(config.DefaultElasticsearchType).
|
||||||
Id(torrentJSON.ID).
|
Id(strconv.FormatUint(uint64(torrentJSON.ID), 10)).
|
||||||
BodyJson(torrentJSON).
|
BodyJson(torrentJSON).
|
||||||
Refresh("true").
|
Refresh("true").
|
||||||
Do(ctx)
|
Do(ctx)
|
||||||
|
@ -203,7 +203,7 @@ type FileJSON struct {
|
||||||
|
|
||||||
// TorrentJSON for torrent model in json for api
|
// TorrentJSON for torrent model in json for api
|
||||||
type TorrentJSON struct {
|
type TorrentJSON struct {
|
||||||
ID string `json:"id"`
|
ID uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
Hash string `json:"hash"`
|
Hash string `json:"hash"`
|
||||||
|
@ -281,7 +281,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
||||||
torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash)
|
torrentlink = fmt.Sprintf(config.TorrentStorageLink, t.Hash)
|
||||||
}
|
}
|
||||||
res := TorrentJSON{
|
res := TorrentJSON{
|
||||||
ID: strconv.FormatUint(uint64(t.ID), 10),
|
ID: t.ID,
|
||||||
Name: t.Name,
|
Name: t.Name,
|
||||||
Status: t.Status,
|
Status: t.Status,
|
||||||
Hash: t.Hash,
|
Hash: t.Hash,
|
||||||
|
|
|
@ -74,7 +74,7 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
for i, torrent := range torrents {
|
for i, torrent := range torrents {
|
||||||
torrentJSON := torrent.ToJSON()
|
torrentJSON := torrent.ToJSON()
|
||||||
feed.Items[i] = &feeds.Item{
|
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,
|
Title: torrent.Name,
|
||||||
Link: &feeds.Link{Href: string(torrentJSON.Magnet)},
|
Link: &feeds.Link{Href: string(torrentJSON.Magnet)},
|
||||||
Description: string(torrentJSON.Description),
|
Description: string(torrentJSON.Description),
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="tr-name">
|
<td class="tr-name">
|
||||||
<a href="{{genRoute "view_torrent" "id" .ID }}">
|
<a href="{{genRoute "view_torrent" "id" ( print .ID ) }}">
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -52,7 +52,7 @@ Your browser does not support the audio element.
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="tr-name home-td">
|
<td class="tr-name home-td">
|
||||||
<a href="{{genRoute "view_torrent" "id" .ID }}">
|
<a href="{{genRoute "view_torrent" "id" ( print .ID ) }}">
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
Référencer dans un nouveau ticket