This commit is contained in:
@@ -573,21 +573,30 @@ 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()
|
||||||
|
}
|
||||||
|
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{
|
pragmas := []string{
|
||||||
`PRAGMA journal_mode=WAL;`,
|
`PRAGMA journal_mode=WAL;`,
|
||||||
`PRAGMA synchronous=NORMAL;`,
|
`PRAGMA synchronous=NORMAL;`,
|
||||||
`PRAGMA temp_store=MEMORY;`,
|
`PRAGMA temp_store=MEMORY;`,
|
||||||
`PRAGMA optimize;`,
|
|
||||||
`PRAGMA busy_timeout=5000;`,
|
`PRAGMA busy_timeout=5000;`,
|
||||||
}
|
}
|
||||||
for _, pragma := range pragmas {
|
for _, pragma := range pragmas {
|
||||||
_, err = execLog(ctx, dbConn, pragma)
|
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 {
|
if logger, ok := ctx.Value("logger").(*slog.Logger); ok && logger != nil {
|
||||||
logger.Debug("Applied SQLite tuning pragma", "pragma", pragma, "error", err)
|
logger.Debug("Applied SQLite tuning pragma", "pragma", pragma, "error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
slog.Warn("failed to apply SQLite tuning pragmas", "error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckpointSQLite forces a WAL checkpoint (truncate) when using SQLite. No-op for other drivers.
|
// CheckpointSQLite forces a WAL checkpoint (truncate) when using SQLite. No-op for other drivers.
|
||||||
|
|||||||
Reference in New Issue
Block a user