Add new option DATABASE_CONNECTION_LIFETIME
This commit is contained in:
parent
e0557d8961
commit
c119a2c011
5 changed files with 28 additions and 3 deletions
|
@ -132,6 +132,7 @@ func Parse() {
|
|||
config.Opts.DatabaseURL(),
|
||||
config.Opts.DatabaseMinConns(),
|
||||
config.Opts.DatabaseMaxConns(),
|
||||
config.Opts.DatabaseConnectionLifetime(),
|
||||
)
|
||||
if err != nil {
|
||||
logger.Fatal("Unable to initialize database connection pool: %v", err)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"miniflux.app/version"
|
||||
)
|
||||
|
@ -34,6 +35,7 @@ const (
|
|||
defaultDatabaseURL = "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
|
||||
defaultDatabaseMaxConns = 20
|
||||
defaultDatabaseMinConns = 1
|
||||
defaultDatabaseConnectionLifetime = 5
|
||||
defaultListenAddr = "127.0.0.1:8080"
|
||||
defaultCertFile = ""
|
||||
defaultKeyFile = ""
|
||||
|
@ -90,6 +92,7 @@ type Options struct {
|
|||
databaseURL string
|
||||
databaseMaxConns int
|
||||
databaseMinConns int
|
||||
databaseConnectionLifetime int
|
||||
runMigrations bool
|
||||
listenAddr string
|
||||
certFile string
|
||||
|
@ -148,6 +151,7 @@ func NewOptions() *Options {
|
|||
databaseURL: defaultDatabaseURL,
|
||||
databaseMaxConns: defaultDatabaseMaxConns,
|
||||
databaseMinConns: defaultDatabaseMinConns,
|
||||
databaseConnectionLifetime: defaultDatabaseConnectionLifetime,
|
||||
runMigrations: defaultRunMigrations,
|
||||
listenAddr: defaultListenAddr,
|
||||
certFile: defaultCertFile,
|
||||
|
@ -249,6 +253,11 @@ func (o *Options) DatabaseMinConns() int {
|
|||
return o.databaseMinConns
|
||||
}
|
||||
|
||||
// DatabaseConnectionLifetime returns the maximum amount of time a connection may be reused.
|
||||
func (o *Options) DatabaseConnectionLifetime() time.Duration {
|
||||
return time.Duration(o.databaseConnectionLifetime) * time.Minute
|
||||
}
|
||||
|
||||
// ListenAddr returns the listen address for the HTTP server.
|
||||
func (o *Options) ListenAddr() string {
|
||||
return o.listenAddr
|
||||
|
@ -484,6 +493,7 @@ func (o *Options) SortedOptions() []*Option {
|
|||
"CREATE_ADMIN": o.createAdmin,
|
||||
"DATABASE_MAX_CONNS": o.databaseMaxConns,
|
||||
"DATABASE_MIN_CONNS": o.databaseMinConns,
|
||||
"DATABASE_CONNECTION_LIFETIME": o.databaseConnectionLifetime,
|
||||
"DATABASE_URL": o.databaseURL,
|
||||
"DEBUG": o.debug,
|
||||
"FETCH_YOUTUBE_WATCH_TIME": o.fetchYouTubeWatchTime,
|
||||
|
|
|
@ -95,6 +95,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
|
|||
p.opts.databaseMaxConns = parseInt(value, defaultDatabaseMaxConns)
|
||||
case "DATABASE_MIN_CONNS":
|
||||
p.opts.databaseMinConns = parseInt(value, defaultDatabaseMinConns)
|
||||
case "DATABASE_CONNECTION_LIFETIME":
|
||||
p.opts.databaseConnectionLifetime = parseInt(value, defaultDatabaseConnectionLifetime)
|
||||
case "RUN_MIGRATIONS":
|
||||
p.opts.runMigrations = parseBool(value, defaultRunMigrations)
|
||||
case "DISABLE_HSTS":
|
||||
|
|
|
@ -7,13 +7,14 @@ package database // import "miniflux.app/database"
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
// Postgresql driver import
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
// NewConnectionPool configures the database connection pool.
|
||||
func NewConnectionPool(dsn string, minConnections, maxConnections int) (*sql.DB, error) {
|
||||
func NewConnectionPool(dsn string, minConnections, maxConnections int, connectionLifetime time.Duration) (*sql.DB, error) {
|
||||
db, err := sql.Open("postgres", dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -21,6 +22,7 @@ func NewConnectionPool(dsn string, minConnections, maxConnections int) (*sql.DB,
|
|||
|
||||
db.SetMaxOpenConns(maxConnections)
|
||||
db.SetMaxIdleConns(minConnections)
|
||||
db.SetConnMaxLifetime(connectionLifetime)
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
|
14
miniflux.1
14
miniflux.1
|
@ -1,5 +1,5 @@
|
|||
.\" Manpage for miniflux.
|
||||
.TH "MINIFLUX" "1" "April 30, 2021" "\ \&" "\ \&"
|
||||
.TH "MINIFLUX" "1" "May 23, 2021" "\ \&" "\ \&"
|
||||
|
||||
.SH NAME
|
||||
miniflux \- Minimalist and opinionated feed reader
|
||||
|
@ -174,6 +174,11 @@ Path to a secret key exposed as a file, it should contain $DATABASE_URL value\&.
|
|||
.br
|
||||
Default is empty\&.
|
||||
.TP
|
||||
.B DATABASE_CONNECTION_LIFETIME
|
||||
Set the maximum amount of time a connection may be reused\&.
|
||||
.br
|
||||
Default is 5 minutes\&.
|
||||
.TP
|
||||
.B DATABASE_MAX_CONNS
|
||||
Maximum number of database connections\&.
|
||||
.br
|
||||
|
@ -400,7 +405,12 @@ Disabled by default\&.
|
|||
.B MAINTENANCE_MESSAGE
|
||||
Define a custom maintenance message\&.
|
||||
.br
|
||||
Default is "Miniflux is currently under maintenance".
|
||||
Default is "Miniflux is currently under maintenance"\&.
|
||||
.TP
|
||||
.B WATCHDOG
|
||||
Enable or disable Systemd watchdog\&.
|
||||
.br
|
||||
Enabled by default\&.
|
||||
|
||||
.SH AUTHORS
|
||||
.P
|
||||
|
|
Loading…
Reference in a new issue