Added settings for max open/idle connections and max connection lifetime (#74)
This commit is contained in:
parent
6b348fad04
commit
802a13cffd
5 changed files with 27 additions and 4 deletions
|
@ -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] 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] Things like list/task order should use queries and not url params
|
||||||
* [x] Fix lint errors
|
* [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
|
* [ ] 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)
|
* [ ] 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
|
* [ ] When giving a team or user access to a list/namespace, they should be reffered to by uuid, not numeric id
|
||||||
|
|
|
@ -33,7 +33,11 @@ database:
|
||||||
# When using sqlite, this is the path where to store the data
|
# When using sqlite, this is the path where to store the data
|
||||||
Path: "./vikunja.db"
|
Path: "./vikunja.db"
|
||||||
# Sets the max open connections to the database. Only used when using mysql.
|
# 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:
|
cache:
|
||||||
# If cache is enabled or not
|
# If cache is enabled or not
|
||||||
|
|
|
@ -76,7 +76,11 @@ database:
|
||||||
# When using sqlite, this is the path where to store the data
|
# When using sqlite, this is the path where to store the data
|
||||||
Path: "./vikunja.db"
|
Path: "./vikunja.db"
|
||||||
# Sets the max open connections to the database. Only used when using mysql.
|
# 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:
|
cache:
|
||||||
# If cache is enabled or not
|
# If cache is enabled or not
|
||||||
|
|
|
@ -57,7 +57,10 @@ func InitConfig() {
|
||||||
viper.SetDefault("database.password", "")
|
viper.SetDefault("database.password", "")
|
||||||
viper.SetDefault("database.database", "vikunja")
|
viper.SetDefault("database.database", "vikunja")
|
||||||
viper.SetDefault("database.path", "./vikunja.db")
|
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
|
// Cacher
|
||||||
viper.SetDefault("cache.enabled", false)
|
viper.SetDefault("cache.enabled", false)
|
||||||
viper.SetDefault("cache.type", "memory")
|
viper.SetDefault("cache.type", "memory")
|
||||||
|
|
13
pkg/db/db.go
13
pkg/db/db.go
|
@ -23,6 +23,8 @@ import (
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql" // Because.
|
_ "github.com/go-sql-driver/mysql" // Because.
|
||||||
_ "github.com/mattn/go-sqlite3" // 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.host"),
|
||||||
viper.GetString("database.database"))
|
viper.GetString("database.database"))
|
||||||
engine, err = xorm.NewEngine("mysql", connStr)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue