Skip to content

Commit ea305f6

Browse files
committedJan 13, 2025
impv(db): update valid tables methods
1 parent c896406 commit ea305f6

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed
 

‎informative-indexer/db/db.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,14 @@ func GetRowCount(ctx context.Context, dbClient Queryable, table string) (int64,
135135
}
136136

137137
func GetRowsToPruneByBlockHeight(ctx context.Context, dbClient Queryable, table string, threshold int64) (pgx.Rows, error) {
138-
if !isValidTableName(table) {
138+
t, ok := ValidTablesMap[table]
139+
if !ok {
139140
return nil, fmt.Errorf("invalid table name: %s", table)
141+
140142
}
141143

142-
var query string
143-
t := ValidTablesMap[table]
144144
columns := getColumns(t)
145-
146-
query = fmt.Sprintf("SELECT %s FROM %s WHERE block_height <= $1", strings.Join(columns, ", "), table)
147-
145+
query := fmt.Sprintf("SELECT %s FROM %s WHERE block_height <= $1", strings.Join(columns, ", "), table)
148146
rows, err := QueryRowsWithTimeout(ctx, dbClient, query, threshold)
149147
if err != nil {
150148
return nil, fmt.Errorf("failed to get rows to prune from table %s: %w", table, err)

‎informative-indexer/db/valid_tables.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ var ValidTablesMap = map[string]ValidTable{
1313
}
1414

1515
func isValidTableName(tableName string) bool {
16-
for validTable, _ := range ValidTablesMap {
17-
if tableName == validTable {
18-
return true
19-
}
20-
}
21-
return false
16+
_, ok := ValidTablesMap[tableName]
17+
return ok
2218
}
2319

2420
func GetValidTableNames() []string {

0 commit comments

Comments
 (0)