Update custom column support to also automatically retry DB errors to further harden against issues like #119

This commit is contained in:
David Dworken 2023-10-30 17:50:47 -07:00
parent 5f9ff9e158
commit f8b515c328
No known key found for this signature in database

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"context" "context"
"database/sql"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -937,15 +938,17 @@ func parseAtomizedToken(ctx context.Context, token string) (string, any, any, er
func getAllCustomColumnNames(ctx context.Context) ([]string, error) { func getAllCustomColumnNames(ctx context.Context) ([]string, error) {
db := hctx.GetDb(ctx) db := hctx.GetDb(ctx)
query := ` rows, err := RetryingDbFunctionWithResult(func() (*sql.Rows, error) {
SELECT DISTINCT json_extract(value, '$.name') as cc_name query := `
FROM history_entries SELECT DISTINCT json_extract(value, '$.name') as cc_name
JOIN json_each(custom_columns) FROM history_entries
WHERE value IS NOT NULL JOIN json_each(custom_columns)
LIMIT 10` WHERE value IS NOT NULL
rows, err := db.Raw(query).Rows() LIMIT 10`
return db.Raw(query).Rows()
})
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to query for list of custom columns: %v", err)
} }
ccNames := make([]string, 0) ccNames := make([]string, 0)
for rows.Next() { for rows.Next() {