Sort comments on Rophako ingest

This commit is contained in:
Noah 2017-12-24 10:24:42 -08:00
parent baaf7bcfac
commit c664c07a74
2 changed files with 10 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -189,6 +190,9 @@ func migrateComments() {
t.Post(new) t.Post(new)
} }
// Re-sort the comments by date.
sort.Sort(comments.ByCreated(t.Comments))
// Check for subscribers // Check for subscribers
subs := legacySubscribers{} subs := legacySubscribers{}
err = inDB.Get(fmt.Sprintf("comments/subscribers/%s", id), &subs) err = inDB.Get(fmt.Sprintf("comments/subscribers/%s", id), &subs)

View File

@ -60,6 +60,12 @@ type Comment struct {
Editing bool `json:"-"` Editing bool `json:"-"`
} }
type ByCreated []*Comment
func (a ByCreated) Len() int { return len(a) }
func (a ByCreated) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByCreated) Less(i, j int) bool { return a[i].Created.Before(a[j].Created) }
// New initializes a new comment thread. // New initializes a new comment thread.
func New(id string) Thread { func New(id string) Thread {
return Thread{ return Thread{