code re-org and bugfix hanging hourly snapshot
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-01-21 09:12:25 +11:00
parent c7c7fd3dc9
commit fd9cc185ce
6 changed files with 113 additions and 56 deletions

View File

@@ -135,12 +135,22 @@ func TableHasRows(ctx context.Context, dbConn *sqlx.DB, table string) (bool, err
if err := ValidateTableName(table); err != nil {
return false, err
}
// Avoid hanging on locked tables; apply a short timeout.
if ctx == nil {
ctx = context.Background()
}
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, 15*time.Second)
defer cancel()
query := fmt.Sprintf(`SELECT 1 FROM %s LIMIT 1`, table)
var exists int
if err := getLog(ctx, dbConn, &exists, query); err != nil {
if err == sql.ErrNoRows {
return false, nil
}
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
return false, nil
}
return false, err
}
return true, nil