sqldb: use uint32 for config values

This commit is contained in:
Elle Mouton
2025-08-14 08:03:28 +02:00
parent d5729845d0
commit f560c4d95b
4 changed files with 18 additions and 18 deletions

View File

@@ -788,13 +788,13 @@ func BenchmarkFindOptimalSQLQueryConfig(b *testing.B) {
// Set the various page sizes we want to test.
//
// NOTE: these are the sqlite paging testing values.
testSizes := []int{20, 50, 100, 150, 500}
testSizes := []uint32{20, 50, 100, 150, 500}
configOption := "MaxPageSize"
if testBatching {
configOption = "MaxBatchSize"
testSizes = []int{
testSizes = []uint32{
50, 100, 150, 200, 250, 300, 350,
}
}
@@ -806,10 +806,10 @@ func BenchmarkFindOptimalSQLQueryConfig(b *testing.B) {
// Set the various page sizes we want to test.
//
// NOTE: these are the postgres paging values.
testSizes = []int{5000, 7000, 10000, 12000}
testSizes = []uint32{5000, 7000, 10000, 12000}
if testBatching {
testSizes = []int{
testSizes = []uint32{
1000, 2000, 5000, 7000, 10000,
}
}
@@ -828,7 +828,7 @@ func BenchmarkFindOptimalSQLQueryConfig(b *testing.B) {
if testBatching {
cfg.MaxBatchSize = size
} else {
cfg.MaxPageSize = int32(size)
cfg.MaxPageSize = size
}
store := connectNativeSQLite(

View File

@@ -283,7 +283,7 @@ func migrateNodes(ctx context.Context, cfg *sqldb.QueryConfig,
batch[id] = node
// Validate batch when full.
if len(batch) >= cfg.MaxBatchSize {
if len(batch) >= int(cfg.MaxBatchSize) {
err := validateBatch()
if err != nil {
return fmt.Errorf("batch validation failed: %w",
@@ -548,7 +548,7 @@ func migrateChannelsAndPolicies(ctx context.Context, cfg *SQLStoreConfig,
dbInfo: dbChanInfo,
}
if len(batch) >= cfg.QueryCfg.MaxBatchSize {
if len(batch) >= int(cfg.QueryCfg.MaxBatchSize) {
// Do batch validation.
err := validateMigratedChannels(ctx, cfg, sqlDB, batch)
if err != nil {
@@ -902,7 +902,7 @@ func migratePruneLog(ctx context.Context, cfg *sqldb.QueryConfig,
batch[height] = *hash
// Validate batch when full.
if len(batch) >= cfg.MaxBatchSize {
if len(batch) >= int(cfg.MaxBatchSize) {
err := validateBatch()
if err != nil {
return fmt.Errorf("batch "+
@@ -1070,7 +1070,7 @@ func migrateClosedSCIDIndex(ctx context.Context, cfg *sqldb.QueryConfig,
batch = append(batch, chanIDB)
// Validate batch when full.
if len(batch) >= cfg.MaxBatchSize {
if len(batch) >= int(cfg.MaxBatchSize) {
err := validateBatch()
if err != nil {
return fmt.Errorf("batch validation failed: %w",
@@ -1251,7 +1251,7 @@ func migrateZombieIndex(ctx context.Context, cfg *sqldb.QueryConfig,
}
// Validate batch when full.
if len(batch) >= cfg.MaxBatchSize {
if len(batch) >= int(cfg.MaxBatchSize) {
err := validateBatch()
if err != nil {
return fmt.Errorf("batch validation failed: %w",

View File

@@ -37,11 +37,11 @@ const (
type QueryConfig struct {
// MaxBatchSize is the maximum number of items included in a batch
// query IN clauses list.
MaxBatchSize int `long:"max-batch-size" description:"The maximum number of items to include in a batch query IN clause. This is used for queries that fetch results based on a list of identifiers."`
MaxBatchSize uint32 `long:"max-batch-size" description:"The maximum number of items to include in a batch query IN clause. This is used for queries that fetch results based on a list of identifiers."`
// MaxPageSize is the maximum number of items returned in a single page
// of results. This is used for paginated queries.
MaxPageSize int32 `long:"max-page-size" description:"The maximum number of items to return in a single page of results. This is used for paginated queries."`
MaxPageSize uint32 `long:"max-page-size" description:"The maximum number of items to return in a single page of results. This is used for paginated queries."`
}
// Validate checks that the QueryConfig values are valid.
@@ -121,9 +121,9 @@ func ExecuteBatchQuery[I any, T any, R any](ctx context.Context,
}
// Process items in pages.
for i := 0; i < len(inputItems); i += cfg.MaxBatchSize {
for i := 0; i < len(inputItems); i += int(cfg.MaxBatchSize) {
// Calculate the end index for this page.
end := i + cfg.MaxBatchSize
end := i + int(cfg.MaxBatchSize)
if end > len(inputItems) {
end = len(inputItems)
}
@@ -189,7 +189,7 @@ func ExecutePaginatedQuery[C any, T any](ctx context.Context, cfg *QueryConfig,
for {
// Fetch the next page.
items, err := queryFunc(ctx, cursor, cfg.MaxPageSize)
items, err := queryFunc(ctx, cursor, int32(cfg.MaxPageSize))
if err != nil {
return fmt.Errorf("failed to fetch page with "+
"cursor %v: %w", cursor, err)
@@ -265,7 +265,7 @@ func ExecuteCollectAndBatchWithSharedDataQuery[C any, T any, I any, D any](
for {
// Step 1: Fetch the next page of items.
items, err := pageQueryFunc(ctx, cursor, cfg.MaxPageSize)
items, err := pageQueryFunc(ctx, cursor, int32(cfg.MaxPageSize))
if err != nil {
return fmt.Errorf("failed to fetch page with "+
"cursor %v: %w", cursor, err)

View File

@@ -341,7 +341,7 @@ func TestExecutePaginatedQuery(t *testing.T) {
tests := []struct {
name string
pageSize int32
pageSize uint32
allItems []testItem
initialCursor int64
queryError error
@@ -592,7 +592,7 @@ func TestExecuteCollectAndBatchWithSharedDataQuery(t *testing.T) {
tests := []struct {
name string
maxPageSize int32
maxPageSize uint32
allRows []channelRow
initialCursor int64
pageQueryError error