fix crash again
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-09 16:06:55 +11:00
parent b70dfcf5be
commit 24bf74ad34

View File

@@ -573,20 +573,29 @@ func ApplySQLiteTuning(ctx context.Context, dbConn *sqlx.DB) {
if strings.ToLower(dbConn.DriverName()) != "sqlite" { if strings.ToLower(dbConn.DriverName()) != "sqlite" {
return return
} }
// Best-effort pragmas; ignore errors to stay safe in constrained environments. if ctx == nil {
var err error ctx = context.Background()
pragmas := []string{
`PRAGMA journal_mode=WAL;`,
`PRAGMA synchronous=NORMAL;`,
`PRAGMA temp_store=MEMORY;`,
`PRAGMA optimize;`,
`PRAGMA busy_timeout=5000;`,
} }
for _, pragma := range pragmas { if err := ensureOncePerDB(dbConn, "sqlite_tuning_pragmas", func() error {
_, err = execLog(ctx, dbConn, pragma) // Best-effort pragmas; keep this list lightweight to avoid long-running startup work.
if logger, ok := ctx.Value("logger").(*slog.Logger); ok && logger != nil { // `PRAGMA optimize` is intentionally excluded from the hourly snapshot hot path.
logger.Debug("Applied SQLite tuning pragma", "pragma", pragma, "error", err) pragmas := []string{
`PRAGMA journal_mode=WAL;`,
`PRAGMA synchronous=NORMAL;`,
`PRAGMA temp_store=MEMORY;`,
`PRAGMA busy_timeout=5000;`,
} }
for _, pragma := range pragmas {
pragmaCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
_, err := execLog(pragmaCtx, dbConn, pragma)
cancel()
if logger, ok := ctx.Value("logger").(*slog.Logger); ok && logger != nil {
logger.Debug("Applied SQLite tuning pragma", "pragma", pragma, "error", err)
}
}
return nil
}); err != nil {
slog.Warn("failed to apply SQLite tuning pragmas", "error", err)
} }
} }