From f560c4d95b0127f569813b91fca949dae8461d94 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 14 Aug 2025 08:03:28 +0200 Subject: [PATCH] sqldb: use uint32 for config values --- graph/db/benchmark_test.go | 10 +++++----- graph/db/sql_migration.go | 10 +++++----- sqldb/paginate.go | 12 ++++++------ sqldb/paginate_test.go | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/graph/db/benchmark_test.go b/graph/db/benchmark_test.go index 58b8cb39a..bdb7954cd 100644 --- a/graph/db/benchmark_test.go +++ b/graph/db/benchmark_test.go @@ -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( diff --git a/graph/db/sql_migration.go b/graph/db/sql_migration.go index 0584914c3..5aea3d335 100644 --- a/graph/db/sql_migration.go +++ b/graph/db/sql_migration.go @@ -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", diff --git a/sqldb/paginate.go b/sqldb/paginate.go index 17e2fd40e..4fd2a9d4d 100644 --- a/sqldb/paginate.go +++ b/sqldb/paginate.go @@ -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) diff --git a/sqldb/paginate_test.go b/sqldb/paginate_test.go index f62bf65b4..20abf422e 100644 --- a/sqldb/paginate_test.go +++ b/sqldb/paginate_test.go @@ -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