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