mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-18 18:16:50 +01:00
sdk: decrease interval between replaceable lists and sets refetch attempts conditionally.
This commit is contained in:
13
sdk/list.go
13
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
|
// but if we haven't tried fetching from the network recently we should do it
|
||||||
lastFetchKey := makeLastFetchKey(actualKind, pubkey)
|
lastFetchKey := makeLastFetchKey(actualKind, pubkey)
|
||||||
lastFetchData, _ := sys.KVStore.Get(lastFetchKey)
|
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)
|
newV := tryFetchListFromNetwork(ctx, sys, pubkey, replaceableIndex, parseTag)
|
||||||
if newV != nil && newV.Event.CreatedAt > v.Event.CreatedAt {
|
if newV != nil && newV.Event.CreatedAt > v.Event.CreatedAt {
|
||||||
v = *newV
|
v = *newV
|
||||||
@@ -140,3 +140,14 @@ func parseItemsFromEventTags[I TagItemWithValue](
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLocalStoreRefreshDaysForKind(kind int) nostr.Timestamp {
|
||||||
|
switch kind {
|
||||||
|
case 0:
|
||||||
|
return 7
|
||||||
|
case 3:
|
||||||
|
return 1
|
||||||
|
default:
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func fetchGenericSets[I TagItemWithValue](
|
|||||||
// but if we haven't tried fetching from the network recently we should do it
|
// but if we haven't tried fetching from the network recently we should do it
|
||||||
lastFetchKey := makeLastFetchKey(actualKind, pubkey)
|
lastFetchKey := makeLastFetchKey(actualKind, pubkey)
|
||||||
lastFetchData, _ := sys.KVStore.Get(lastFetchKey)
|
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)
|
newV := tryFetchSetsFromNetwork(ctx, sys, pubkey, addressableIndex, parseTag)
|
||||||
|
|
||||||
// unlike for lists, when fetching sets we will blindly trust whatever we get from the network
|
// unlike for lists, when fetching sets we will blindly trust whatever we get from the network
|
||||||
|
|||||||
Reference in New Issue
Block a user