From 627b8eeae6b7e3ad11d2b5b0b3f9f46c4aca055f Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 17 Jan 2023 13:29:44 +0100 Subject: [feature] Tune sqlite pragmas (#1349) * sqlite pragma tuning * use formatuint * add sqlite busy timeout * fix incorrect cache size format * update envparsing test * add sqlite tuning flags to cli * set sqlite timeout to 30s default --- testrig/config.go | 19 +++++++++++++------ testrig/db.go | 12 +++--------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'testrig') diff --git a/testrig/config.go b/testrig/config.go index fff9f8fd3..315e52bb9 100644 --- a/testrig/config.go +++ b/testrig/config.go @@ -19,6 +19,9 @@ package testrig import ( + "time" + + "codeberg.org/gruf/go-bytesize" "github.com/coreos/go-oidc/v3/oidc" "github.com/superseriousbusiness/gotosocial/internal/config" ) @@ -43,12 +46,16 @@ var testDefaults = config.Configuration{ Port: 8080, TrustedProxies: []string{"127.0.0.1/32", "::1"}, - DbType: "sqlite", - DbAddress: ":memory:", - DbPort: 5432, - DbUser: "postgres", - DbPassword: "postgres", - DbDatabase: "postgres", + DbType: "sqlite", + DbAddress: ":memory:", + DbPort: 5432, + DbUser: "postgres", + DbPassword: "postgres", + DbDatabase: "postgres", + DbSqliteJournalMode: "WAL", + DbSqliteSynchronous: "NORMAL", + DbSqliteCacheSize: 64 * bytesize.MiB, + DbSqliteBusyTimeout: time.Second * 30, WebTemplateBaseDir: "./web/template/", WebAssetBaseDir: "./web/assets/", diff --git a/testrig/db.go b/testrig/db.go index 4304050cf..65ec391a7 100644 --- a/testrig/db.go +++ b/testrig/db.go @@ -73,15 +73,11 @@ var testModels = []interface{}{ // value as the port instead. func NewTestDB() db.DB { if alternateAddress := os.Getenv("GTS_DB_ADDRESS"); alternateAddress != "" { - config.Config(func(cfg *config.Configuration) { - cfg.DbAddress = alternateAddress - }) + config.SetDbAddress(alternateAddress) } if alternateDBType := os.Getenv("GTS_DB_TYPE"); alternateDBType != "" { - config.Config(func(cfg *config.Configuration) { - cfg.DbType = alternateDBType - }) + config.SetDbType(alternateDBType) } if alternateDBPort := os.Getenv("GTS_DB_PORT"); alternateDBPort != "" { @@ -89,9 +85,7 @@ func NewTestDB() db.DB { if err != nil { panic(err) } - config.Config(func(cfg *config.Configuration) { - cfg.DbPort = int(port) - }) + config.SetDbPort(int(port)) } var state state.State -- cgit v1.2.3