From 82f2fbdb99304b38524da71857d016ad4ccb75d9 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 7 Apr 2026 17:39:21 -0300 Subject: [PATCH] sdk: a bunch of more list loaders. --- sdk/lists_event.go | 24 +++++++- sdk/lists_profile.go | 33 +++++++++++ sdk/lists_relay.go | 22 +++++++ sdk/replaceable_loader.go | 30 ++++++---- sdk/system.go | 118 +++++++++++++++++++++++++------------- 5 files changed, 175 insertions(+), 52 deletions(-) diff --git a/sdk/lists_event.go b/sdk/lists_event.go index 3393d72..d2a49be 100644 --- a/sdk/lists_event.go +++ b/sdk/lists_event.go @@ -22,6 +22,17 @@ func (sys *System) FetchBookmarkList(ctx context.Context, pubkey nostr.PubKey) G return ml } +func (sys *System) FetchProfileBadgesList(ctx context.Context, pubkey nostr.PubKey) GenericList[string, EventRef] { + sys.profileBadgesListCacheOnce.Do(func() { + if sys.ProfileBadgesListCache == nil { + sys.ProfileBadgesListCache = cache_memory.New[GenericList[string, EventRef]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10008, kind_10008, parseEventRef, sys.ProfileBadgesListCache) + return ml +} + func (sys *System) FetchPinList(ctx context.Context, pubkey nostr.PubKey) GenericList[string, EventRef] { sys.pinListCacheOnce.Do(func() { if sys.PinListCache == nil { @@ -33,6 +44,17 @@ func (sys *System) FetchPinList(ctx context.Context, pubkey nostr.PubKey) Generi return ml } +func (sys *System) FetchGitRepositoryList(ctx context.Context, pubkey nostr.PubKey) GenericList[string, EventRef] { + sys.gitRepositoryListCacheOnce.Do(func() { + if sys.GitRepositoryListCache == nil { + sys.GitRepositoryListCache = cache_memory.New[GenericList[string, EventRef]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10018, kind_10018, parseEventRef, sys.GitRepositoryListCache) + return ml +} + func parseEventRef(tag nostr.Tag) (evr EventRef, ok bool) { if len(tag) < 2 { return evr, false @@ -54,5 +76,5 @@ func parseEventRef(tag nostr.Tag) (evr EventRef, ok bool) { return evr, false } - return evr, false + return evr, true } diff --git a/sdk/lists_profile.go b/sdk/lists_profile.go index 2381ee2..cde95a3 100644 --- a/sdk/lists_profile.go +++ b/sdk/lists_profile.go @@ -39,6 +39,39 @@ func (sys *System) FetchMuteList(ctx context.Context, pubkey nostr.PubKey) Gener return ml } +func (sys *System) FetchMediaFollowList(ctx context.Context, pubkey nostr.PubKey) GenericList[nostr.PubKey, ProfileRef] { + sys.mediaFollowListCacheOnce.Do(func() { + if sys.MediaFollowListCache == nil { + sys.MediaFollowListCache = cache_memory.New[GenericList[nostr.PubKey, ProfileRef]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10020, kind_10020, parseProfileRef, sys.MediaFollowListCache) + return ml +} + +func (sys *System) FetchGoodWikiAuthorList(ctx context.Context, pubkey nostr.PubKey) GenericList[nostr.PubKey, ProfileRef] { + sys.goodWikiAuthorListCacheOnce.Do(func() { + if sys.GoodWikiAuthorListCache == nil { + sys.GoodWikiAuthorListCache = cache_memory.New[GenericList[nostr.PubKey, ProfileRef]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10101, kind_10101, parseProfileRef, sys.GoodWikiAuthorListCache) + return ml +} + +func (sys *System) FetchGitAuthorList(ctx context.Context, pubkey nostr.PubKey) GenericList[nostr.PubKey, ProfileRef] { + sys.gitAuthorListCacheOnce.Do(func() { + if sys.GitAuthorListCache == nil { + sys.GitAuthorListCache = cache_memory.New[GenericList[nostr.PubKey, ProfileRef]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10017, kind_10017, parseProfileRef, sys.GitAuthorListCache) + return ml +} + func (sys *System) FetchFollowSets(ctx context.Context, pubkey nostr.PubKey) GenericSets[nostr.PubKey, ProfileRef] { sys.followSetsCacheOnce.Do(func() { if sys.FollowSetsCache == nil { diff --git a/sdk/lists_relay.go b/sdk/lists_relay.go index 42fe17f..8864b6f 100644 --- a/sdk/lists_relay.go +++ b/sdk/lists_relay.go @@ -46,6 +46,28 @@ func (sys *System) FetchSearchRelayList(ctx context.Context, pubkey nostr.PubKey return ml } +func (sys *System) FetchDMRelayList(ctx context.Context, pubkey nostr.PubKey) GenericList[string, RelayURL] { + sys.dmRelayListCacheOnce.Do(func() { + if sys.DMRelayListCache == nil { + sys.DMRelayListCache = cache_memory.New[GenericList[string, RelayURL]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10050, kind_10050, parseRelayURL, sys.DMRelayListCache) + return ml +} + +func (sys *System) FetchGoodWikiRelayList(ctx context.Context, pubkey nostr.PubKey) GenericList[string, RelayURL] { + sys.goodWikiRelayListCacheOnce.Do(func() { + if sys.GoodWikiRelayListCache == nil { + sys.GoodWikiRelayListCache = cache_memory.New[GenericList[string, RelayURL]](1000) + } + }) + + ml, _ := fetchGenericList(sys, ctx, pubkey, 10102, kind_10102, parseRelayURL, sys.GoodWikiRelayListCache) + return ml +} + func (sys *System) FetchRelaySets(ctx context.Context, pubkey nostr.PubKey) GenericSets[string, RelayURL] { sys.relaySetsCacheOnce.Do(func() { if sys.RelaySetsCache == nil { diff --git a/sdk/replaceable_loader.go b/sdk/replaceable_loader.go index 2401ff8..21d0745 100644 --- a/sdk/replaceable_loader.go +++ b/sdk/replaceable_loader.go @@ -22,32 +22,42 @@ const ( kind_10001 replaceableIndex = 3 kind_10002 replaceableIndex = 4 kind_10003 replaceableIndex = 5 - kind_10004 replaceableIndex = 6 - kind_10005 replaceableIndex = 7 - kind_10006 replaceableIndex = 8 - kind_10007 replaceableIndex = 9 - kind_10015 replaceableIndex = 10 - kind_10019 replaceableIndex = 11 - kind_10030 replaceableIndex = 12 + kind_10006 replaceableIndex = 6 + kind_10007 replaceableIndex = 7 + kind_10015 replaceableIndex = 8 + kind_10019 replaceableIndex = 9 + kind_10030 replaceableIndex = 10 + kind_10008 replaceableIndex = 11 + kind_10017 replaceableIndex = 12 + kind_10018 replaceableIndex = 13 + kind_10020 replaceableIndex = 14 + kind_10050 replaceableIndex = 15 + kind_10101 replaceableIndex = 16 + kind_10102 replaceableIndex = 17 ) type EventResult dataloader.Result[*nostr.Event] func (sys *System) initializeReplaceableDataloaders() { - sys.replaceableLoaders = make([]*dataloader.Loader[nostr.PubKey, nostr.Event], 13) + sys.replaceableLoaders = make([]*dataloader.Loader[nostr.PubKey, nostr.Event], 18) sys.replaceableLoaders[kind_0] = sys.createReplaceableDataloader(0) sys.replaceableLoaders[kind_3] = sys.createReplaceableDataloader(3) sys.replaceableLoaders[kind_10000] = sys.createReplaceableDataloader(10000) sys.replaceableLoaders[kind_10001] = sys.createReplaceableDataloader(10001) sys.replaceableLoaders[kind_10002] = sys.createReplaceableDataloader(10002) sys.replaceableLoaders[kind_10003] = sys.createReplaceableDataloader(10003) - sys.replaceableLoaders[kind_10004] = sys.createReplaceableDataloader(10004) - sys.replaceableLoaders[kind_10005] = sys.createReplaceableDataloader(10005) sys.replaceableLoaders[kind_10006] = sys.createReplaceableDataloader(10006) sys.replaceableLoaders[kind_10007] = sys.createReplaceableDataloader(10007) sys.replaceableLoaders[kind_10015] = sys.createReplaceableDataloader(10015) sys.replaceableLoaders[kind_10019] = sys.createReplaceableDataloader(10019) sys.replaceableLoaders[kind_10030] = sys.createReplaceableDataloader(10030) + sys.replaceableLoaders[kind_10008] = sys.createReplaceableDataloader(10008) + sys.replaceableLoaders[kind_10017] = sys.createReplaceableDataloader(10017) + sys.replaceableLoaders[kind_10018] = sys.createReplaceableDataloader(10018) + sys.replaceableLoaders[kind_10020] = sys.createReplaceableDataloader(10020) + sys.replaceableLoaders[kind_10050] = sys.createReplaceableDataloader(10050) + sys.replaceableLoaders[kind_10101] = sys.createReplaceableDataloader(10101) + sys.replaceableLoaders[kind_10102] = sys.createReplaceableDataloader(10102) } func (sys *System) createReplaceableDataloader(kind nostr.Kind) *dataloader.Loader[nostr.PubKey, nostr.Event] { diff --git a/sdk/system.go b/sdk/system.go index 22d81c0..4e968f5 100644 --- a/sdk/system.go +++ b/sdk/system.go @@ -30,47 +30,83 @@ import ( // default they're set to in-memory stores, but ideally persisteable // implementations should be given (some alternatives are provided in subpackages). type System struct { - KVStore kvstore.KVStore - metadataCacheOnce sync.Once - MetadataCache cache.Cache32[ProfileMetadata] - relayListCacheOnce sync.Once - RelayListCache cache.Cache32[GenericList[string, Relay]] - followListCacheOnce sync.Once - FollowListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] - muteListCacheOnce sync.Once - MuteListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] - bookmarkListCacheOnce sync.Once - BookmarkListCache cache.Cache32[GenericList[string, EventRef]] - pinListCacheOnce sync.Once - PinListCache cache.Cache32[GenericList[string, EventRef]] - blockedRelayListCacheOnce sync.Once - BlockedRelayListCache cache.Cache32[GenericList[string, RelayURL]] - searchRelayListCacheOnce sync.Once - SearchRelayListCache cache.Cache32[GenericList[string, RelayURL]] - topicListCacheOnce sync.Once - TopicListCache cache.Cache32[GenericList[string, Topic]] - relaySetsCacheOnce sync.Once - RelaySetsCache cache.Cache32[GenericSets[string, RelayURL]] - followSetsCacheOnce sync.Once - FollowSetsCache cache.Cache32[GenericSets[nostr.PubKey, ProfileRef]] - topicSetsCacheOnce sync.Once - TopicSetsCache cache.Cache32[GenericSets[string, Topic]] - zapProviderCacheOnce sync.Once - ZapProviderCache cache.Cache32[nostr.PubKey] - mintKeysCacheOnce sync.Once - MintKeysCache cache.Cache32[map[uint64]*btcec.PublicKey] - nutZapInfoCacheOnce sync.Once - NutZapInfoCache cache.Cache32[NutZapInfo] - Hints hints.HintsDB - Pool *nostr.Pool - RelayListRelays *RelayStream - FollowListRelays *RelayStream - MetadataRelays *RelayStream - FallbackRelays *RelayStream - JustIDRelays *RelayStream - UserSearchRelays *RelayStream - NoteSearchRelays *RelayStream - Store eventstore.Store + KVStore kvstore.KVStore + metadataCacheOnce sync.Once + MetadataCache cache.Cache32[ProfileMetadata] + relayListCacheOnce sync.Once + RelayListCache cache.Cache32[GenericList[string, Relay]] + followListCacheOnce sync.Once + FollowListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] + muteListCacheOnce sync.Once + MuteListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] + bookmarkListCacheOnce sync.Once + BookmarkListCache cache.Cache32[GenericList[string, EventRef]] + pinListCacheOnce sync.Once + PinListCache cache.Cache32[GenericList[string, EventRef]] + profileBadgesListCacheOnce sync.Once + ProfileBadgesListCache cache.Cache32[GenericList[string, EventRef]] + gitRepositoryListCacheOnce sync.Once + GitRepositoryListCache cache.Cache32[GenericList[string, EventRef]] + blockedRelayListCacheOnce sync.Once + BlockedRelayListCache cache.Cache32[GenericList[string, RelayURL]] + searchRelayListCacheOnce sync.Once + SearchRelayListCache cache.Cache32[GenericList[string, RelayURL]] + dmRelayListCacheOnce sync.Once + DMRelayListCache cache.Cache32[GenericList[string, RelayURL]] + goodWikiRelayListCacheOnce sync.Once + GoodWikiRelayListCache cache.Cache32[GenericList[string, RelayURL]] + topicListCacheOnce sync.Once + TopicListCache cache.Cache32[GenericList[string, Topic]] + mediaFollowListCacheOnce sync.Once + MediaFollowListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] + goodWikiAuthorListCacheOnce sync.Once + GoodWikiAuthorListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] + gitAuthorListCacheOnce sync.Once + GitAuthorListCache cache.Cache32[GenericList[nostr.PubKey, ProfileRef]] + relaySetsCacheOnce sync.Once + RelaySetsCache cache.Cache32[GenericSets[string, RelayURL]] + followSetsCacheOnce sync.Once + FollowSetsCache cache.Cache32[GenericSets[nostr.PubKey, ProfileRef]] + topicSetsCacheOnce sync.Once + TopicSetsCache cache.Cache32[GenericSets[string, Topic]] + bookmarkSetsCacheOnce sync.Once + BookmarkSetsCache cache.Cache32[GenericSets[string, EventRef]] + curationSetsCacheOnce sync.Once + CurationSetsCache cache.Cache32[GenericSets[string, EventRef]] + videoCurationSetsCacheOnce sync.Once + VideoCurationSetsCache cache.Cache32[GenericSets[string, EventRef]] + pictureCurationSetsCacheOnce sync.Once + PictureCurationSetsCache cache.Cache32[GenericSets[string, EventRef]] + kindMuteSetsCacheOnce sync.Once + KindMuteSetsCache cache.Cache32[GenericSets[nostr.PubKey, ProfileRef]] + badgeSetsCacheOnce sync.Once + BadgeSetsCache cache.Cache32[GenericSets[string, EventRef]] + releaseArtifactSetsCacheOnce sync.Once + ReleaseArtifactSetsCache cache.Cache32[GenericSets[string, EventRef]] + appCurationSetsCacheOnce sync.Once + AppCurationSetsCache cache.Cache32[GenericSets[string, EventRef]] + calendarSetsCacheOnce sync.Once + CalendarSetsCache cache.Cache32[GenericSets[string, EventRef]] + starterPackSetsCacheOnce sync.Once + StarterPackSetsCache cache.Cache32[GenericSets[nostr.PubKey, ProfileRef]] + mediaStarterPackSetsCacheOnce sync.Once + MediaStarterPackSetsCache cache.Cache32[GenericSets[nostr.PubKey, ProfileRef]] + zapProviderCacheOnce sync.Once + ZapProviderCache cache.Cache32[nostr.PubKey] + mintKeysCacheOnce sync.Once + MintKeysCache cache.Cache32[map[uint64]*btcec.PublicKey] + nutZapInfoCacheOnce sync.Once + NutZapInfoCache cache.Cache32[NutZapInfo] + Hints hints.HintsDB + Pool *nostr.Pool + RelayListRelays *RelayStream + FollowListRelays *RelayStream + MetadataRelays *RelayStream + FallbackRelays *RelayStream + JustIDRelays *RelayStream + UserSearchRelays *RelayStream + NoteSearchRelays *RelayStream + Store eventstore.Store Publisher nostr.Publisher