Fix converting invalid json coming from ES (#1100)
Cette révision appartient à :
Parent
8469cdaa6a
révision
76f08e99ae
2 fichiers modifiés avec 12 ajouts et 9 suppressions
|
@ -231,21 +231,24 @@ func (p *TorrentParam) Find(client *elastic.Client) (int64, []model.Torrent, err
|
|||
log.Infof("Query '%s' took %d milliseconds.", p.NameLike, result.TookInMillis)
|
||||
log.Infof("Amount of results %d.", result.TotalHits())
|
||||
|
||||
torrents := make([]model.Torrent, len(result.Hits.Hits))
|
||||
var torrents []model.Torrent
|
||||
var torrentCount int64
|
||||
torrentCount = 0
|
||||
//torrents := make([]model.Torrent, len(result.Hits.Hits))
|
||||
if len(result.Hits.Hits) <= 0 {
|
||||
return 0, nil, nil
|
||||
}
|
||||
for i, hit := range result.Hits.Hits {
|
||||
// Deserialize hit.Source into a Tweet (could also be just a map[string]interface{}).
|
||||
for _, hit := range result.Hits.Hits {
|
||||
var tJson model.TorrentJSON
|
||||
err := json.Unmarshal(*hit.Source, &tJson)
|
||||
if err != nil {
|
||||
log.Errorf("Cannot unmarshal elasticsearch torrent: %s", err)
|
||||
if err == nil {
|
||||
torrents = append(torrents, tJson.ToTorrent())
|
||||
torrentCount += 1
|
||||
} else {
|
||||
log.Infof("Cannot unmarshal elasticsearch torrent: %s", err)
|
||||
}
|
||||
torrent := tJson.ToTorrent()
|
||||
torrents[i] = torrent
|
||||
}
|
||||
return result.TotalHits(), torrents, nil
|
||||
return torrentCount, torrents, nil
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ func (t *TorrentJSON) ToTorrent() Torrent {
|
|||
}
|
||||
// Need to add +00:00 at the end because ES doesn't store it by default
|
||||
dateFixed := t.Date
|
||||
if t.Date[len(t.Date)-6] != '+' {
|
||||
if len(dateFixed) > 6 && dateFixed[len(dateFixed)-6] != '+' {
|
||||
dateFixed += "Z"
|
||||
}
|
||||
date, err := time.Parse(time.RFC3339, dateFixed)
|
||||
|
|
Référencer dans un nouveau ticket