sdk: only instantiate caches by default when they are necessary.

This commit is contained in:
fiatjaf
2025-02-11 14:14:48 -03:00
parent 7189cd7e02
commit 3de002aca1
5 changed files with 55 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import (
"strings"
"github.com/nbd-wtf/go-nostr"
cache_memory "github.com/nbd-wtf/go-nostr/sdk/cache/memory"
)
type EventRef struct{ nostr.Pointer }
@@ -13,11 +14,19 @@ type EventRef struct{ nostr.Pointer }
func (e EventRef) Value() string { return e.Pointer.AsTagReference() }
func (sys *System) FetchBookmarkList(ctx context.Context, pubkey string) GenericList[EventRef] {
if sys.BookmarkListCache == nil {
sys.BookmarkListCache = cache_memory.New32[GenericList[EventRef]](1000)
}
ml, _ := fetchGenericList(sys, ctx, pubkey, 10003, kind_10003, parseEventRef, sys.BookmarkListCache)
return ml
}
func (sys *System) FetchPinList(ctx context.Context, pubkey string) GenericList[EventRef] {
if sys.PinListCache == nil {
sys.PinListCache = cache_memory.New32[GenericList[EventRef]](1000)
}
ml, _ := fetchGenericList(sys, ctx, pubkey, 10001, kind_10001, parseEventRef, sys.PinListCache)
return ml
}