init ua parser once (#3883)
This commit is contained in:
+4
-4
@@ -177,15 +177,15 @@ func ChunkProtoBatch[T proto.Message](batch []T, target int) [][]T {
|
||||
var chunks [][]T
|
||||
var start, size int
|
||||
for i, m := range batch {
|
||||
if s := proto.Size(m); size+s > target {
|
||||
s := proto.Size(m)
|
||||
if size+s > target {
|
||||
if start < i {
|
||||
chunks = append(chunks, batch[start:i])
|
||||
}
|
||||
start = i
|
||||
size = s
|
||||
} else {
|
||||
size += s
|
||||
size = 0
|
||||
}
|
||||
size += s
|
||||
}
|
||||
if start < len(batch) {
|
||||
chunks = append(chunks, batch[start:])
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -63,12 +62,14 @@ func TestChunkProtoBatch(t *testing.T) {
|
||||
|
||||
target := 64 * 1024
|
||||
batches := ChunkProtoBatch(updates, target)
|
||||
var count int
|
||||
for _, b := range batches {
|
||||
var sum int
|
||||
for _, m := range b {
|
||||
sum += proto.Size(m)
|
||||
count++
|
||||
}
|
||||
require.True(t, sum < target || len(b) == 1, "batch size exceeds target")
|
||||
}
|
||||
fmt.Println(len(batches))
|
||||
require.Equal(t, len(updates), count)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user