go-nostr/sdk/utils.go

47 lines
1022 B
Go
Raw Permalink Normal View History

package sdk
import (
2025-01-05 14:19:03 -03:00
"math"
"strings"
"sync"
"time"
)
var (
_dtnmtoah map[string]time.Time
_dtnmtoahLock sync.Mutex
)
// IsVirtualRelay returns true if the given normalized relay URL shouldn't be considered for outbox-model calculations.
func IsVirtualRelay(url string) bool {
if len(url) < 6 {
// this is just invalid
return true
}
if strings.HasPrefix(url, "wss://feeds.nostr.band") ||
strings.HasPrefix(url, "wss://filter.nostr.wine") ||
strings.HasPrefix(url, "wss://cache") {
return true
}
return false
}
2025-01-05 14:19:03 -03:00
// PerQueryLimitInBatch tries to make an educated guess for the batch size given the total filter limit and
2025-01-05 14:19:03 -03:00
// the number of abstract queries we'll be conducting at the same time
func PerQueryLimitInBatch(totalFilterLimit int, numberOfQueries int) int {
2025-01-05 14:19:03 -03:00
if numberOfQueries == 1 || totalFilterLimit*numberOfQueries < 50 {
return totalFilterLimit
}
return max(4,
int(
math.Ceil(
float64(totalFilterLimit)/
math.Pow(float64(numberOfQueries), 0.4),
),
2025-01-05 14:19:03 -03:00
),
)
}