aboutsummaryrefslogtreecommitdiff
path: root/mediaapi/storage
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-05-01 13:34:53 +0100
committerGitHub <noreply@github.com>2020-05-01 13:34:53 +0100
commitf7cfa758864cc9849ce8b0539895283417b75eb0 (patch)
treefd75b5363172dacd7eab3b47c9a3ab1b7c4721bb /mediaapi/storage
parent908108c23e47df5fbf0d6629b676e105abd2a564 (diff)
Limit database connections (#980, #564) (#998)
* Limit database connections (#564) - Add new options to the config file database: max_open_conns: 100 max_idle_conns: 2 conn_max_lifetime: -1 - Implement connection parameter setup on the *DB (database/sql) in internal/sqlutil/trace.go:Open() - Propagate the values in the form of DbProperties interface via all the Open() and NewDatabase() functions Signed-off-by: Tomas Jirka <tomas.jirka@email.cz> * Fix wasm builds * Remove file accidentally added from working tree Co-authored-by: Tomas Jirka <tomas.jirka@email.cz>
Diffstat (limited to 'mediaapi/storage')
-rw-r--r--mediaapi/storage/postgres/storage.go5
-rw-r--r--mediaapi/storage/sqlite3/storage.go2
-rw-r--r--mediaapi/storage/storage.go9
-rw-r--r--mediaapi/storage/storage_wasm.go6
4 files changed, 14 insertions, 8 deletions
diff --git a/mediaapi/storage/postgres/storage.go b/mediaapi/storage/postgres/storage.go
index 18126b15..4ddfc8fd 100644
--- a/mediaapi/storage/postgres/storage.go
+++ b/mediaapi/storage/postgres/storage.go
@@ -21,6 +21,7 @@ import (
// Import the postgres database driver.
_ "github.com/lib/pq"
+ "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/types"
"github.com/matrix-org/gomatrixserverlib"
@@ -33,10 +34,10 @@ type Database struct {
}
// Open opens a postgres database.
-func Open(dataSourceName string) (*Database, error) {
+func Open(dataSourceName string, dbProperties common.DbProperties) (*Database, error) {
var d Database
var err error
- if d.db, err = sqlutil.Open("postgres", dataSourceName); err != nil {
+ if d.db, err = sqlutil.Open("postgres", dataSourceName, dbProperties); err != nil {
return nil, err
}
if err = d.statements.prepare(d.db); err != nil {
diff --git a/mediaapi/storage/sqlite3/storage.go b/mediaapi/storage/sqlite3/storage.go
index abafecf2..8fa2e537 100644
--- a/mediaapi/storage/sqlite3/storage.go
+++ b/mediaapi/storage/sqlite3/storage.go
@@ -37,7 +37,7 @@ type Database struct {
func Open(dataSourceName string) (*Database, error) {
var d Database
var err error
- if d.db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName); err != nil {
+ if d.db, err = sqlutil.Open(common.SQLiteDriverName(), dataSourceName, nil); err != nil {
return nil, err
}
if err = d.statements.prepare(d.db); err != nil {
diff --git a/mediaapi/storage/storage.go b/mediaapi/storage/storage.go
index c533477c..6589c830 100644
--- a/mediaapi/storage/storage.go
+++ b/mediaapi/storage/storage.go
@@ -19,22 +19,23 @@ package storage
import (
"net/url"
+ "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/mediaapi/storage/postgres"
"github.com/matrix-org/dendrite/mediaapi/storage/sqlite3"
)
// Open opens a postgres database.
-func Open(dataSourceName string) (Database, error) {
+func Open(dataSourceName string, dbProperties common.DbProperties) (Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
- return postgres.Open(dataSourceName)
+ return postgres.Open(dataSourceName, dbProperties)
}
switch uri.Scheme {
case "postgres":
- return postgres.Open(dataSourceName)
+ return postgres.Open(dataSourceName, dbProperties)
case "file":
return sqlite3.Open(dataSourceName)
default:
- return postgres.Open(dataSourceName)
+ return postgres.Open(dataSourceName, dbProperties)
}
}
diff --git a/mediaapi/storage/storage_wasm.go b/mediaapi/storage/storage_wasm.go
index 92f0ad13..3c39e5d3 100644
--- a/mediaapi/storage/storage_wasm.go
+++ b/mediaapi/storage/storage_wasm.go
@@ -18,11 +18,15 @@ import (
"fmt"
"net/url"
+ "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/mediaapi/storage/sqlite3"
)
// Open opens a postgres database.
-func Open(dataSourceName string) (Database, error) {
+func Open(
+ dataSourceName string,
+ dbProperties common.DbProperties, // nolint:unparam
+) (Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
return nil, fmt.Errorf("Cannot use postgres implementation")