Added settings for max open/idle connections and max connection lifetime (#74)
continuous-integration/drone/push Build is passing Details

This commit is contained in:
konrad 2019-05-25 05:49:52 +00:00 committed by Gitea
parent 6b348fad04
commit 802a13cffd
5 changed files with 27 additions and 4 deletions

View File

@ -213,6 +213,7 @@ Sorry for some of them being in German, I'll tranlate them at some point.
* [x] Re-check all `{List|Namespace}{User|Team}` if really all parameters need to be exposed via json or are overwritten via param anyway.
* [x] Things like list/task order should use queries and not url params
* [x] Fix lint errors
* [x] Add settings for max open/idle connections and max connection lifetime
* [ ] Reminders should use an extra table so we can make reverse lookups aka "give me all tasks with reminders in this period" which we'll need for things like email reminders notifications
* [ ] Teams and users should also have uuids (for users these can be the username)
* [ ] When giving a team or user access to a list/namespace, they should be reffered to by uuid, not numeric id

View File

@ -33,7 +33,11 @@ database:
# When using sqlite, this is the path where to store the data
Path: "./vikunja.db"
# Sets the max open connections to the database. Only used when using mysql.
openconnections: 100
maxopenconnections: 100
# Sets the maximum number of idle connections to the db.
maxidleconnections: 50
# The maximum lifetime of a single db connection in miliseconds.
maxconnectionlifetime: 10000
cache:
# If cache is enabled or not

View File

@ -76,7 +76,11 @@ database:
# When using sqlite, this is the path where to store the data
Path: "./vikunja.db"
# Sets the max open connections to the database. Only used when using mysql.
openconnections: 100
maxopenconnections: 100
# Sets the maximum number of idle connections to the db.
maxidleconnections: 50
# The maximum lifetime of a single db connection in miliseconds.
maxconnectionlifetime: 10000
cache:
# If cache is enabled or not

View File

@ -57,7 +57,10 @@ func InitConfig() {
viper.SetDefault("database.password", "")
viper.SetDefault("database.database", "vikunja")
viper.SetDefault("database.path", "./vikunja.db")
viper.SetDefault("database.openconnections", 100)
viper.SetDefault("database.maxopenconnections", 100)
viper.SetDefault("database.maxidleconnections", 50)
viper.SetDefault("database.maxconnectionlifetime", 10000)
// Cacher
viper.SetDefault("cache.enabled", false)
viper.SetDefault("cache.type", "memory")

View File

@ -23,6 +23,8 @@ import (
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
"github.com/spf13/viper"
"strconv"
"time"
_ "github.com/go-sql-driver/mysql" // Because.
_ "github.com/mattn/go-sqlite3" // Because.
@ -64,7 +66,16 @@ func initMysqlEngine() (engine *xorm.Engine, err error) {
viper.GetString("database.host"),
viper.GetString("database.database"))
engine, err = xorm.NewEngine("mysql", connStr)
engine.SetMaxOpenConns(viper.GetInt("database.openconnections"))
if err != nil {
return
}
engine.SetMaxOpenConns(viper.GetInt("database.maxopenconnections"))
engine.SetMaxIdleConns(viper.GetInt("database.maxidleconnections"))
max, err := time.ParseDuration(strconv.Itoa(viper.GetInt("database.maxconnectionlifetime")) + `ms`)
if err != nil {
return
}
engine.SetConnMaxLifetime(max)
return
}