sort scores

This commit is contained in:
Andre Medeiros 2022-05-26 18:17:49 -04:00
parent 8dc4ac350e
commit e7faf73834

View file

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"sort"
"strconv"
"time"
@ -199,6 +200,10 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
return
}
sort.SliceStable(tps.Children, func(i, j int) bool {
return tps.Children[i].Score > tps.Children[j].Score
})
posts := make([]string, tps.Count)
for i, post := range tps.Children {
posts[i] = fmt.Sprintf("%s: %d", post.Title, post.Score)