From 522e647db08075dd1a9d66d1146e6b3aa48a6481 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 11 Oct 2018 18:39:53 +0200 Subject: [PATCH] Added config for database max connections --- docs/config.md | 3 +++ models/config.go | 1 + models/models.go | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 8767bd8d..0ee6c32d 100644 --- a/docs/config.md +++ b/docs/config.md @@ -45,6 +45,9 @@ database: Path: "./vikunja.db" # Whether to show mysql queries or not. Useful for debugging. showqueries: "false" + # Sets the max open connections to the database. Only used when using mysql. + openconnections: 100 + cache: # If cache is enabled or not diff --git a/models/config.go b/models/config.go index 05df346a..bdd5f86a 100644 --- a/models/config.go +++ b/models/config.go @@ -27,6 +27,7 @@ func InitConfig() (err error) { viper.SetDefault("database.database", "vikunja") viper.SetDefault("database.path", "./vikunja.db") viper.SetDefault("database.showqueries", false) + viper.SetDefault("database.openconnections", 100) // Cacher viper.SetDefault("cache.enabled", false) viper.SetDefault("cache.type", "memory") diff --git a/models/models.go b/models/models.go index 8c5988c0..71c8fb5d 100644 --- a/models/models.go +++ b/models/models.go @@ -27,7 +27,9 @@ func getEngine() (*xorm.Engine, error) { viper.GetString("database.password"), viper.GetString("database.host"), viper.GetString("database.database")) - return xorm.NewEngine("mysql", connStr) + e, err := xorm.NewEngine("mysql", connStr) + e.SetMaxOpenConns(viper.GetInt("database.openconnections")) + return e, err } // Otherwise use sqlite