sqlite: execute PRAGMA optimize on startup

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-09-06 19:35:18 +02:00
parent db35a55a3d
commit 1b928ef6b2
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF

View file

@ -215,7 +215,7 @@ func initializeSQLiteProvider(basePath string) error {
providerLog(logger.LevelDebug, "sqlite database handle created, connection string: %q", connectionString)
dbHandle.SetMaxOpenConns(1)
provider = &SQLiteProvider{dbHandle: dbHandle}
return nil
return executePragmaOptimize(dbHandle)
}
func (p *SQLiteProvider) checkAvailability() error {
@ -773,6 +773,14 @@ func (p *SQLiteProvider) normalizeError(err error, fieldType int) error {
return err
}
func executePragmaOptimize(dbHandle *sql.DB) error {
ctx, cancel := context.WithTimeout(context.Background(), defaultSQLQueryTimeout)
defer cancel()
_, err := dbHandle.ExecContext(ctx, "PRAGMA optimize;")
return err
}
/*func setPragmaFK(dbHandle *sql.DB, value string) error {
ctx, cancel := context.WithTimeout(context.Background(), longSQLQueryTimeout)
defer cancel()