From 85c268b8e24ba45377b1fd30842c4c3b1bcb7d88 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 21 Jan 2025 17:41:28 -0300 Subject: [PATCH] sdk: fix for when we have no record of ever trying to fetch replaceables. --- sdk/list.go | 2 +- sdk/metadata.go | 2 +- sdk/set.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/list.go b/sdk/list.go index be09e72..1c891f0 100644 --- a/sdk/list.go +++ b/sdk/list.go @@ -68,7 +68,7 @@ func fetchGenericList[I TagItemWithValue]( // but if we haven't tried fetching from the network recently we should do it lastFetchKey := makeLastFetchKey(actualKind, pubkey) lastFetchData, _ := sys.KVStore.Get(lastFetchKey) - if nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { + if lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { newV := tryFetchListFromNetwork(ctx, sys, pubkey, replaceableIndex, parseTag) if newV != nil && newV.Event.CreatedAt > v.Event.CreatedAt { v = *newV diff --git a/sdk/metadata.go b/sdk/metadata.go index c371aef..1aa7389 100644 --- a/sdk/metadata.go +++ b/sdk/metadata.go @@ -108,7 +108,7 @@ func (sys *System) FetchProfileMetadata(ctx context.Context, pubkey string) (pm // but if we haven't tried fetching from the network recently we should do it lastFetchKey := makeLastFetchKey(0, pubkey) lastFetchData, _ := sys.KVStore.Get(lastFetchKey) - if nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { + if lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { newM := sys.tryFetchMetadataFromNetwork(ctx, pubkey) if newM != nil && newM.Event.CreatedAt > pm.Event.CreatedAt { pm = *newM diff --git a/sdk/set.go b/sdk/set.go index 64b7820..561fd7e 100644 --- a/sdk/set.go +++ b/sdk/set.go @@ -57,7 +57,7 @@ func fetchGenericSets[I TagItemWithValue]( // but if we haven't tried fetching from the network recently we should do it lastFetchKey := makeLastFetchKey(actualKind, pubkey) lastFetchData, _ := sys.KVStore.Get(lastFetchKey) - if nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { + if lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { newV := tryFetchSetsFromNetwork(ctx, sys, pubkey, addressableIndex, parseTag) // unlike for lists, when fetching sets we will blindly trust whatever we get from the network