badger/lmdb: fix tag sorting when they are small.
This commit is contained in:
@@ -3,7 +3,6 @@ package badger
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
|
||||
"github.com/fiatjaf/eventstore"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
@@ -87,7 +86,7 @@ func getIndexKeysForEvent(evt *nostr.Event, idx []byte) [][]byte {
|
||||
}
|
||||
|
||||
// ~ by tagvalue+date
|
||||
slices.SortFunc(evt.Tags, func(a, b nostr.Tag) int { return strings.Compare(a[1], b[1]) })
|
||||
slices.SortFunc(evt.Tags, eventstore.TagSorter)
|
||||
for i, tag := range evt.Tags {
|
||||
if len(tag) < 2 || len(tag[0]) != 1 || len(tag[1]) == 0 || len(tag[1]) > 100 {
|
||||
// not indexable
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package eventstore
|
||||
|
||||
import "github.com/nbd-wtf/go-nostr"
|
||||
import (
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
func isOlder(previous, next *nostr.Event) bool {
|
||||
return previous.CreatedAt < next.CreatedAt ||
|
||||
|
||||
@@ -3,7 +3,6 @@ package lmdb
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
|
||||
"github.com/PowerDNS/lmdb-go/lmdb"
|
||||
"github.com/fiatjaf/eventstore"
|
||||
@@ -79,7 +78,7 @@ func (b *LMDBBackend) getIndexKeysForEvent(evt *nostr.Event) []key {
|
||||
}
|
||||
|
||||
// ~ by tagvalue+date
|
||||
slices.SortFunc(evt.Tags, func(a, b nostr.Tag) int { return strings.Compare(a[1], b[1]) })
|
||||
slices.SortFunc(evt.Tags, eventstore.TagSorter)
|
||||
for i, tag := range evt.Tags {
|
||||
if len(tag) < 2 || len(tag[0]) != 1 || len(tag[1]) == 0 || len(tag[1]) > 100 {
|
||||
// not indexable
|
||||
|
||||
15
utils.go
15
utils.go
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/hex"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
func GetAddrTagElements(tagValue string) (kind uint16, pkb []byte, d string) {
|
||||
@@ -17,3 +19,16 @@ func GetAddrTagElements(tagValue string) (kind uint16, pkb []byte, d string) {
|
||||
}
|
||||
return 0, nil, ""
|
||||
}
|
||||
|
||||
func TagSorter(a, b nostr.Tag) int {
|
||||
if len(a) < 2 {
|
||||
if len(b) < 2 {
|
||||
return 0
|
||||
}
|
||||
return -1
|
||||
}
|
||||
if len(b) < 2 {
|
||||
return 1
|
||||
}
|
||||
return strings.Compare(a[1], b[1])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user