From e89b817f7d91b50c572558758aaf0d5ad7f4a709 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 14 Jan 2025 20:55:37 -0300 Subject: [PATCH] sdk: remove skipFetch from fetchGenericList() --- .gitignore | 1 + sdk/list.go | 19 ++++++++----------- sdk/lists_event.go | 4 ++-- sdk/lists_profile.go | 6 +++--- sdk/lists_relay.go | 8 ++++---- sdk/lists_topics.go | 4 ++-- sdk/outbox.go | 2 +- sdk/set.go | 21 +++++++++------------ 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index af2ce2f..b1195ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ go-nostr libsecp256k1 +knowledge.md diff --git a/sdk/list.go b/sdk/list.go index f7a9a1c..6657488 100644 --- a/sdk/list.go +++ b/sdk/list.go @@ -34,7 +34,6 @@ func fetchGenericList[I TagItemWithValue]( replaceableIndex replaceableIndex, parseTag func(nostr.Tag) (I, bool), cache cache.Cache32[GenericList[I]], - skipFetch bool, ) (fl GenericList[I], fromInternal bool) { // we have 24 mutexes, so we can load up to 24 lists at the same time, but if we do the same exact // call that will do it only once, the subsequent ones will wait for a result to be cached @@ -67,17 +66,15 @@ func fetchGenericList[I TagItemWithValue]( return v, true } - if !skipFetch { - thunk := sys.replaceableLoaders[replaceableIndex].Load(ctx, pubkey) - evt, err := thunk() - if err == nil { - items := parseItemsFromEventTags(evt, parseTag) - v.Items = items - sys.StoreRelay.Publish(ctx, *evt) - } - cache.SetWithTTL(pubkey, v, time.Hour*6) - valueWasJustCached[lockIdx] = true + thunk := sys.replaceableLoaders[replaceableIndex].Load(ctx, pubkey) + evt, err := thunk() + if err == nil { + items := parseItemsFromEventTags(evt, parseTag) + v.Items = items + sys.StoreRelay.Publish(ctx, *evt) } + cache.SetWithTTL(pubkey, v, time.Hour*6) + valueWasJustCached[lockIdx] = true return v, false } diff --git a/sdk/lists_event.go b/sdk/lists_event.go index fcf30cd..1822cc2 100644 --- a/sdk/lists_event.go +++ b/sdk/lists_event.go @@ -13,12 +13,12 @@ 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] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10003, kind_10003, parseEventRef, sys.BookmarkListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10003, kind_10003, parseEventRef, sys.BookmarkListCache) return ml } func (sys *System) FetchPinList(ctx context.Context, pubkey string) GenericList[EventRef] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10001, kind_10001, parseEventRef, sys.PinListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10001, kind_10001, parseEventRef, sys.PinListCache) return ml } diff --git a/sdk/lists_profile.go b/sdk/lists_profile.go index 60b312e..eb0174e 100644 --- a/sdk/lists_profile.go +++ b/sdk/lists_profile.go @@ -17,17 +17,17 @@ type ProfileRef struct { func (f ProfileRef) Value() string { return f.Pubkey } func (sys *System) FetchFollowList(ctx context.Context, pubkey string) GenericList[ProfileRef] { - fl, _ := fetchGenericList(sys, ctx, pubkey, 3, kind_3, parseProfileRef, sys.FollowListCache, false) + fl, _ := fetchGenericList(sys, ctx, pubkey, 3, kind_3, parseProfileRef, sys.FollowListCache) return fl } func (sys *System) FetchMuteList(ctx context.Context, pubkey string) GenericList[ProfileRef] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10000, kind_10000, parseProfileRef, sys.MuteListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10000, kind_10000, parseProfileRef, sys.MuteListCache) return ml } func (sys *System) FetchFollowSets(ctx context.Context, pubkey string) GenericSets[ProfileRef] { - ml, _ := fetchGenericSets(sys, ctx, pubkey, 30000, kind_30000, parseProfileRef, sys.FollowSetsCache, false) + ml, _ := fetchGenericSets(sys, ctx, pubkey, 30000, kind_30000, parseProfileRef, sys.FollowSetsCache) return ml } diff --git a/sdk/lists_relay.go b/sdk/lists_relay.go index bae4799..7b41b0a 100644 --- a/sdk/lists_relay.go +++ b/sdk/lists_relay.go @@ -19,22 +19,22 @@ type RelayURL string func (r RelayURL) Value() string { return string(r) } func (sys *System) FetchRelayList(ctx context.Context, pubkey string) GenericList[Relay] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10002, kind_10002, parseRelayFromKind10002, sys.RelayListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10002, kind_10002, parseRelayFromKind10002, sys.RelayListCache) return ml } func (sys *System) FetchBlockedRelayList(ctx context.Context, pubkey string) GenericList[RelayURL] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10006, kind_10006, parseRelayURL, sys.BlockedRelayListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10006, kind_10006, parseRelayURL, sys.BlockedRelayListCache) return ml } func (sys *System) FetchSearchRelayList(ctx context.Context, pubkey string) GenericList[RelayURL] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10007, kind_10007, parseRelayURL, sys.SearchRelayListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10007, kind_10007, parseRelayURL, sys.SearchRelayListCache) return ml } func (sys *System) FetchRelaySets(ctx context.Context, pubkey string) GenericSets[RelayURL] { - ml, _ := fetchGenericSets(sys, ctx, pubkey, 30002, kind_30002, parseRelayURL, sys.RelaySetsCache, false) + ml, _ := fetchGenericSets(sys, ctx, pubkey, 30002, kind_30002, parseRelayURL, sys.RelaySetsCache) return ml } diff --git a/sdk/lists_topics.go b/sdk/lists_topics.go index 78d477e..15f1889 100644 --- a/sdk/lists_topics.go +++ b/sdk/lists_topics.go @@ -11,12 +11,12 @@ type Topic string func (r Topic) Value() string { return string(r) } func (sys *System) FetchTopicList(ctx context.Context, pubkey string) GenericList[Topic] { - ml, _ := fetchGenericList(sys, ctx, pubkey, 10015, kind_10015, parseTopicString, sys.TopicListCache, false) + ml, _ := fetchGenericList(sys, ctx, pubkey, 10015, kind_10015, parseTopicString, sys.TopicListCache) return ml } func (sys *System) FetchTopicSets(ctx context.Context, pubkey string) GenericSets[Topic] { - ml, _ := fetchGenericSets(sys, ctx, pubkey, 30015, kind_30015, parseTopicString, sys.TopicSetsCache, false) + ml, _ := fetchGenericSets(sys, ctx, pubkey, 30015, kind_30015, parseTopicString, sys.TopicSetsCache) return ml } diff --git a/sdk/outbox.go b/sdk/outbox.go index 6ba4996..9804ee5 100644 --- a/sdk/outbox.go +++ b/sdk/outbox.go @@ -18,7 +18,7 @@ func (sys *System) FetchOutboxRelays(ctx context.Context, pubkey string, n int) } // if we have it cached that means we have at least tried to fetch recently and it won't be tried again - fetchGenericList(sys, ctx, pubkey, 10002, kind_10002, parseRelayFromKind10002, sys.RelayListCache, false) + fetchGenericList(sys, ctx, pubkey, 10002, kind_10002, parseRelayFromKind10002, sys.RelayListCache) relays := sys.Hints.TopN(pubkey, 6) if len(relays) == 0 { diff --git a/sdk/set.go b/sdk/set.go index 2a2aa3a..68c62ea 100644 --- a/sdk/set.go +++ b/sdk/set.go @@ -26,7 +26,6 @@ func fetchGenericSets[I TagItemWithValue]( addressableIndex addressableIndex, parseTag func(nostr.Tag) (I, bool), cache cache.Cache32[GenericSets[I]], - skipFetch bool, ) (fl GenericSets[I], fromInternal bool) { // we have 24 mutexes, so we can load up to 24 lists at the same time, but if we do the same exact // call that will do it only once, the subsequent ones will wait for a result to be cached @@ -59,19 +58,17 @@ func fetchGenericSets[I TagItemWithValue]( return v, true } - if !skipFetch { - thunk := sys.addressableLoaders[addressableIndex].Load(ctx, pubkey) - events, err := thunk() - if err == nil { - sets := parseSetsFromEvents(events, parseTag) - v.Sets = sets - for _, evt := range events { - sys.StoreRelay.Publish(ctx, *evt) - } + thunk := sys.addressableLoaders[addressableIndex].Load(ctx, pubkey) + events, err := thunk() + if err == nil { + sets := parseSetsFromEvents(events, parseTag) + v.Sets = sets + for _, evt := range events { + sys.StoreRelay.Publish(ctx, *evt) } - cache.SetWithTTL(pubkey, v, time.Hour*6) - valueWasJustCached[lockIdx] = true } + cache.SetWithTTL(pubkey, v, time.Hour*6) + valueWasJustCached[lockIdx] = true return v, false }