From 7be4b02236ea9ca323df209ab2d55f9c967573d9 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 5 Jan 2025 14:19:03 -0300 Subject: [PATCH] sdk: BatchSizePerNumberOfQueries() --- sdk/utils.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk/utils.go b/sdk/utils.go index 6956195..75fceeb 100644 --- a/sdk/utils.go +++ b/sdk/utils.go @@ -1,6 +1,7 @@ package sdk import ( + "math" "strings" "sync" "time" @@ -26,3 +27,17 @@ func IsVirtualRelay(url string) bool { return false } + +// BatchSizePerNumberOfQueries tries to make an educated guess for the batch size given the total filter limit and +// the number of abstract queries we'll be conducting at the same time +func BatchSizePerNumberOfQueries(totalFilterLimit int, numberOfQueries int) int { + if numberOfQueries == 1 || totalFilterLimit*numberOfQueries < 50 { + return totalFilterLimit + } + + return int( + math.Ceil( + math.Pow(float64(totalFilterLimit), 0.80) / math.Pow(float64(numberOfQueries), 0.71), + ), + ) +}