fix: UDP-logged QSOs fall back to the offline outbox on DB failure (were silently lost); speed up MySQL connect (batch migration checks into 1 query, connect direct-to-DB first) — was ~40s on a high-latency link
This commit is contained in:
+19
-7
@@ -198,14 +198,26 @@ func migrate(conn *sql.DB, translate func(string) string) error {
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
for _, name := range names {
|
||||
var dummy string
|
||||
err := conn.QueryRow(`SELECT name FROM schema_migrations WHERE name = ?`, name).Scan(&dummy)
|
||||
if err == nil {
|
||||
continue // already applied
|
||||
// Fetch every applied migration name in ONE query rather than one round-trip
|
||||
// per migration. On a high-latency remote MySQL those 20+ SELECTs dominated the
|
||||
// connect time (each RTT × migration count) — the whole logbook connect could
|
||||
// take tens of seconds. One SELECT + an in-memory set is effectively instant.
|
||||
applied := map[string]bool{}
|
||||
if rows, err := conn.Query(`SELECT name FROM schema_migrations`); err == nil {
|
||||
for rows.Next() {
|
||||
var n string
|
||||
if rows.Scan(&n) == nil {
|
||||
applied[n] = true
|
||||
}
|
||||
}
|
||||
if err != sql.ErrNoRows {
|
||||
return fmt.Errorf("check migration %s: %w", name, err)
|
||||
rows.Close()
|
||||
} else {
|
||||
return fmt.Errorf("read applied migrations: %w", err)
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
if applied[name] {
|
||||
continue // already applied
|
||||
}
|
||||
content, err := migrationsFS.ReadFile("migrations/" + name)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user