mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-08-09 04:31:47 +02:00
sdk: BatchSizePerNumberOfQueries()
This commit is contained in:
15
sdk/utils.go
15
sdk/utils.go
@@ -1,6 +1,7 @@
|
|||||||
package sdk
|
package sdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -26,3 +27,17 @@ func IsVirtualRelay(url string) bool {
|
|||||||
|
|
||||||
return false
|
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),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user