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" {
return
}
// Best-effort pragmas; ignore errors to stay safe in constrained environments.
var err error
pragmas := []string{
`PRAGMA journal_mode=WAL;`,
`PRAGMA synchronous=NORMAL;`,
`PRAGMA temp_store=MEMORY;`,
`PRAGMA optimize;`,
`PRAGMA busy_timeout=5000;`,
if ctx == nil {
ctx = context.Background()
}
for _, pragma := range pragmas {
_, err = execLog(ctx, dbConn, pragma)
if logger, ok := ctx.Value("logger").(*slog.Logger); ok && logger != nil {
logger.Debug("Applied SQLite tuning pragma", "pragma", pragma, "error", err)
if err := ensureOncePerDB(dbConn, "sqlite_tuning_pragmas", func() error {
// Best-effort pragmas; keep this list lightweight to avoid long-running startup work.
// `PRAGMA optimize` is intentionally excluded from the hourly snapshot hot path.
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)
}
}