Remove duplicates in the relays list before fetching last notes

This commit is contained in:
Daniele Tonon
2023-07-12 17:53:17 +02:00
parent 0cbb4918e6
commit 9dbd4d6d40
2 changed files with 13 additions and 0 deletions

View File

@@ -143,6 +143,7 @@ func getLastNotes(ctx context.Context, code string) []*nostr.Event {
relays = append(relays, getRelay())
relays = append(relays, getRelay())
relays = unique(relays)
events := pool.SubManyEose(ctx, relays, nostr.Filters{
{
Kinds: []int{nostr.KindTextNote},

View File

@@ -324,3 +324,15 @@ func mdToHTML(md string) string {
return output
}
func unique(strSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range strSlice {
if _, ok := keys[entry]; !ok {
keys[entry] = true
list = append(list, entry)
}
}
return list
}