From 26da7967dcbb5908960817e3d39a94f82bfbaafb Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 4 Feb 2025 19:27:57 -0300 Subject: [PATCH] sdk: decrease interval between replaceable lists and sets refetch attempts conditionally. --- sdk/list.go | 13 ++++++++++++- sdk/set.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sdk/list.go b/sdk/list.go index 1c891f0..95db850 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 lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { + if lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > getLocalStoreRefreshDaysForKind(actualKind)*24*60*60 { newV := tryFetchListFromNetwork(ctx, sys, pubkey, replaceableIndex, parseTag) if newV != nil && newV.Event.CreatedAt > v.Event.CreatedAt { v = *newV @@ -140,3 +140,14 @@ func parseItemsFromEventTags[I TagItemWithValue]( } return result } + +func getLocalStoreRefreshDaysForKind(kind int) nostr.Timestamp { + switch kind { + case 0: + return 7 + case 3: + return 1 + default: + return 3 + } +} diff --git a/sdk/set.go b/sdk/set.go index 561fd7e..2d6a98b 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 lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > 7*24*60*60 { + if lastFetchData == nil || nostr.Now()-decodeTimestamp(lastFetchData) > getLocalStoreRefreshDaysForKind(actualKind)*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