more efficient sorting.

This commit is contained in:
fiatjaf
2023-07-12 10:44:12 -03:00
parent eac5b4c78b
commit 512d91e773

View File

@@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"sort"
"time" "time"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
@@ -163,10 +162,7 @@ func getLastNotes(ctx context.Context, code string) []*nostr.Event {
}) })
lastNotes := make([]*nostr.Event, 0, 20) lastNotes := make([]*nostr.Event, 0, 20)
for event := range events { for event := range events {
lastNotes = append(lastNotes, event) lastNotes = nostr.InsertEventIntoDescendingList(lastNotes, event)
} }
sort.Slice(lastNotes, func(i, j int) bool {
return lastNotes[i].CreatedAt.Time().After(lastNotes[j].CreatedAt.Time())
})
return lastNotes return lastNotes
} }