define a nostr.Kind type for event kinds, make adjustments everywhere and fix some horrible bugs with mmm, lmdb and badger querying and deleting.
This commit is contained in:
@@ -28,7 +28,7 @@ func (sys *System) initializeAddressableDataloaders() {
|
||||
sys.addressableLoaders[kind_30030] = sys.createAddressableDataloader(30030)
|
||||
}
|
||||
|
||||
func (sys *System) createAddressableDataloader(kind uint16) *dataloader.Loader[nostr.PubKey, []nostr.Event] {
|
||||
func (sys *System) createAddressableDataloader(kind nostr.Kind) *dataloader.Loader[nostr.PubKey, []nostr.Event] {
|
||||
return dataloader.NewBatchedLoader(
|
||||
func(ctxs []context.Context, pubkeys []nostr.PubKey) map[nostr.PubKey]dataloader.Result[[]nostr.Event] {
|
||||
return sys.batchLoadAddressableEvents(ctxs, kind, pubkeys)
|
||||
@@ -42,7 +42,7 @@ func (sys *System) createAddressableDataloader(kind uint16) *dataloader.Loader[n
|
||||
|
||||
func (sys *System) batchLoadAddressableEvents(
|
||||
ctxs []context.Context,
|
||||
kind uint16,
|
||||
kind nostr.Kind,
|
||||
pubkeys []nostr.PubKey,
|
||||
) map[nostr.PubKey]dataloader.Result[[]nostr.Event] {
|
||||
batchSize := len(pubkeys)
|
||||
@@ -77,7 +77,7 @@ func (sys *System) batchLoadAddressableEvents(
|
||||
dfilter = nostr.DirectedFilter{
|
||||
Relay: relay,
|
||||
Filter: nostr.Filter{
|
||||
Kinds: []uint16{kind},
|
||||
Kinds: []nostr.Kind{kind},
|
||||
Authors: make([]nostr.PubKey, 0, batchSize-i /* this and all pubkeys after this can be added */),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func makePubkeyStreamKey(prefix byte, pubkey nostr.PubKey) []byte {
|
||||
func (sys *System) StreamLiveFeed(
|
||||
ctx context.Context,
|
||||
pubkeys []nostr.PubKey,
|
||||
kinds []uint16,
|
||||
kinds []nostr.Kind,
|
||||
) (<-chan nostr.Event, error) {
|
||||
events := make(chan nostr.Event)
|
||||
|
||||
@@ -102,7 +102,7 @@ func (sys *System) StreamLiveFeed(
|
||||
func (sys *System) FetchFeedPage(
|
||||
ctx context.Context,
|
||||
pubkeys []nostr.PubKey,
|
||||
kinds []uint16,
|
||||
kinds []nostr.Kind,
|
||||
until nostr.Timestamp,
|
||||
totalLimit int,
|
||||
) ([]nostr.Event, error) {
|
||||
|
||||
@@ -128,7 +128,7 @@ func TestStreamLiveFeed(t *testing.T) {
|
||||
go sys.Pool.PublishMany(ctx, []string{"ws://localhost:48482", "ws://localhost:48483"}, evt2)
|
||||
|
||||
// start streaming events for both pubkeys
|
||||
events, err := sys.StreamLiveFeed(ctx, []nostr.PubKey{pk1, pk2}, []uint16{1})
|
||||
events, err := sys.StreamLiveFeed(ctx, []nostr.PubKey{pk1, pk2}, []nostr.Kind{1})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start streaming: %v", err)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func fetchGenericList[V comparable, I TagItemWithValue[V]](
|
||||
sys *System,
|
||||
ctx context.Context,
|
||||
pubkey nostr.PubKey,
|
||||
actualKind uint16,
|
||||
actualKind nostr.Kind,
|
||||
replaceableIndex replaceableIndex,
|
||||
parseTag func(nostr.Tag) (I, bool),
|
||||
cache cache.Cache32[GenericList[V, I]],
|
||||
@@ -39,7 +39,7 @@ func fetchGenericList[V comparable, I TagItemWithValue[V]](
|
||||
// call that will do it only once, the subsequent ones will wait for a result to be cached
|
||||
// and then return it from cache -- 13 is an arbitrary index for the pubkey
|
||||
n := pubkey[7]
|
||||
lockIdx := (uint16(n) + actualKind) % 60
|
||||
lockIdx := (nostr.Kind(n) + actualKind) % 60
|
||||
genericListMutexes[lockIdx].Lock()
|
||||
|
||||
if valueWasJustCached[lockIdx] {
|
||||
@@ -57,7 +57,7 @@ func fetchGenericList[V comparable, I TagItemWithValue[V]](
|
||||
|
||||
v := GenericList[V, I]{PubKey: pubkey}
|
||||
|
||||
for evt := range sys.Store.QueryEvents(nostr.Filter{Kinds: []uint16{actualKind}, Authors: []nostr.PubKey{pubkey}}) {
|
||||
for evt := range sys.Store.QueryEvents(nostr.Filter{Kinds: []nostr.Kind{actualKind}, Authors: []nostr.PubKey{pubkey}}) {
|
||||
// ok, we found something locally
|
||||
items := parseItemsFromEventTags(evt, parseTag)
|
||||
v.Event = &evt
|
||||
@@ -138,7 +138,7 @@ func parseItemsFromEventTags[V comparable, I TagItemWithValue[V]](
|
||||
return result
|
||||
}
|
||||
|
||||
func getLocalStoreRefreshDaysForKind(kind uint16) nostr.Timestamp {
|
||||
func getLocalStoreRefreshDaysForKind(kind nostr.Kind) nostr.Timestamp {
|
||||
switch kind {
|
||||
case 0:
|
||||
return 7
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
var kvStoreLastFetchPrefix = byte('f')
|
||||
|
||||
func makeLastFetchKey(kind uint16, pubkey nostr.PubKey) []byte {
|
||||
func makeLastFetchKey(kind nostr.Kind, pubkey nostr.PubKey) []byte {
|
||||
buf := make([]byte, 1+5+32)
|
||||
buf[0] = kvStoreLastFetchPrefix
|
||||
binary.LittleEndian.PutUint32(buf[1:], uint32(kind))
|
||||
|
||||
@@ -110,7 +110,7 @@ func (sys *System) FetchProfileMetadata(ctx context.Context, pubkey nostr.PubKey
|
||||
|
||||
pm.PubKey = pubkey
|
||||
|
||||
for evt := range sys.Store.QueryEvents(nostr.Filter{Kinds: []uint16{0}, Authors: []nostr.PubKey{pubkey}}) {
|
||||
for evt := range sys.Store.QueryEvents(nostr.Filter{Kinds: []nostr.Kind{0}, Authors: []nostr.PubKey{pubkey}}) {
|
||||
// ok, we found something locally
|
||||
pm, _ = ParseMetadata(evt)
|
||||
pm.PubKey = pubkey
|
||||
|
||||
@@ -48,7 +48,7 @@ func (sys *System) initializeReplaceableDataloaders() {
|
||||
sys.replaceableLoaders[kind_10030] = sys.createReplaceableDataloader(10030)
|
||||
}
|
||||
|
||||
func (sys *System) createReplaceableDataloader(kind uint16) *dataloader.Loader[nostr.PubKey, nostr.Event] {
|
||||
func (sys *System) createReplaceableDataloader(kind nostr.Kind) *dataloader.Loader[nostr.PubKey, nostr.Event] {
|
||||
return dataloader.NewBatchedLoader(
|
||||
func(ctxs []context.Context, pubkeys []nostr.PubKey) map[nostr.PubKey]dataloader.Result[nostr.Event] {
|
||||
return sys.batchLoadReplaceableEvents(ctxs, kind, pubkeys)
|
||||
@@ -62,7 +62,7 @@ func (sys *System) createReplaceableDataloader(kind uint16) *dataloader.Loader[n
|
||||
|
||||
func (sys *System) batchLoadReplaceableEvents(
|
||||
ctxs []context.Context,
|
||||
kind uint16,
|
||||
kind nostr.Kind,
|
||||
pubkeys []nostr.PubKey,
|
||||
) map[nostr.PubKey]dataloader.Result[nostr.Event] {
|
||||
batchSize := len(pubkeys)
|
||||
@@ -98,7 +98,7 @@ func (sys *System) batchLoadReplaceableEvents(
|
||||
dfilter = nostr.DirectedFilter{
|
||||
Relay: relay,
|
||||
Filter: nostr.Filter{
|
||||
Kinds: []uint16{kind},
|
||||
Kinds: []nostr.Kind{kind},
|
||||
Authors: make([]nostr.PubKey, 0, batchSize-i /* this and all pubkeys after this can be added */),
|
||||
},
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func (sys *System) batchLoadReplaceableEvents(
|
||||
}
|
||||
}
|
||||
|
||||
func (sys *System) determineRelaysToQuery(ctx context.Context, pubkey nostr.PubKey, kind uint16) []string {
|
||||
func (sys *System) determineRelaysToQuery(ctx context.Context, pubkey nostr.PubKey, kind nostr.Kind) []string {
|
||||
var relays []string
|
||||
|
||||
// search in specific relays for user
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestMetadataAndEvents(t *testing.T) {
|
||||
|
||||
// fetch notes
|
||||
filter := nostr.Filter{
|
||||
Kinds: []uint16{1},
|
||||
Kinds: []nostr.Kind{1},
|
||||
Authors: []nostr.PubKey{meta.PubKey},
|
||||
Limit: 5,
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ func fetchGenericSets[V comparable, I TagItemWithValue[V]](
|
||||
sys *System,
|
||||
ctx context.Context,
|
||||
pubkey nostr.PubKey,
|
||||
actualKind uint16,
|
||||
actualKind nostr.Kind,
|
||||
addressableIndex addressableIndex,
|
||||
parseTag func(nostr.Tag) (I, bool),
|
||||
cache cache.Cache32[GenericSets[V, I]],
|
||||
) (fl GenericSets[V, I], fromInternal bool) {
|
||||
n := pubkey[7]
|
||||
lockIdx := (uint16(n) + actualKind) % 60
|
||||
lockIdx := (nostr.Kind(n) + actualKind) % 60
|
||||
genericListMutexes[lockIdx].Lock()
|
||||
|
||||
if valueWasJustCached[lockIdx] {
|
||||
@@ -47,7 +47,7 @@ func fetchGenericSets[V comparable, I TagItemWithValue[V]](
|
||||
v := GenericSets[V, I]{PubKey: pubkey}
|
||||
|
||||
events := slices.Collect(
|
||||
sys.Store.QueryEvents(nostr.Filter{Kinds: []uint16{actualKind}, Authors: []nostr.PubKey{pubkey}}),
|
||||
sys.Store.QueryEvents(nostr.Filter{Kinds: []nostr.Kind{actualKind}, Authors: []nostr.PubKey{pubkey}}),
|
||||
)
|
||||
if len(events) != 0 {
|
||||
// ok, we found something locally
|
||||
|
||||
@@ -84,7 +84,7 @@ func (sys *System) FetchSpecificEvent(
|
||||
author = v.PublicKey
|
||||
filter.Authors = []nostr.PubKey{v.PublicKey}
|
||||
filter.Tags = nostr.TagMap{"d": []string{v.Identifier}}
|
||||
filter.Kinds = []uint16{v.Kind}
|
||||
filter.Kinds = []nostr.Kind{v.Kind}
|
||||
relays = append(relays, v.Relays...)
|
||||
relays = appendUnique(relays, sys.FallbackRelays.Next())
|
||||
fallback = append(fallback, sys.FallbackRelays.Next(), sys.FallbackRelays.Next())
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fiatjaf.com/nostr/sdk/hints"
|
||||
)
|
||||
|
||||
func (sys *System) TrackQueryAttempts(relay string, author nostr.PubKey, kind uint16) {
|
||||
func (sys *System) TrackQueryAttempts(relay string, author nostr.PubKey, kind nostr.Kind) {
|
||||
if IsVirtualRelay(relay) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user