Skip to content

Commit

Permalink
sdk: BatchSizePerNumberOfQueries()
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Jan 13, 2025
1 parent 36ddf1e commit 7be4b02
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sdk/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sdk

import (
"math"
"strings"
"sync"
"time"
Expand All @@ -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),
),
)
}

0 comments on commit 7be4b02

Please sign in to comment.