aboutsummaryrefslogtreecommitdiff
path: root/mediaapi/storage
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-17 12:09:45 +0100
committerGitHub <noreply@github.com>2023-03-17 11:09:45 +0000
commit5579121c6f27105342a2aea05cf9a3119d73cecb (patch)
tree1d8b7bec90079b6f693585d306c19019ea426870 /mediaapi/storage
parentd88f71ab71a60348518f7fa6735ac9f0bfb472c3 (diff)
Preparations for removing `BaseDendrite` (#3016)
Preparations to actually remove/replace `BaseDendrite`. Quite a few changes: - SyncAPI accepts an `fulltext.Indexer` interface (fulltext is removed from `BaseDendrite`) - Caches are removed from `BaseDendrite` - Introduces a `Router` struct (likely to change) - also fixes #2903 - Introduces a `sqlutil.ConnectionManager`, which should remove `base.DatabaseConnection` later on - probably more
Diffstat (limited to 'mediaapi/storage')
-rw-r--r--mediaapi/storage/postgres/mediaapi.go5
-rw-r--r--mediaapi/storage/sqlite3/mediaapi.go5
-rw-r--r--mediaapi/storage/storage.go8
-rw-r--r--mediaapi/storage/storage_test.go4
-rw-r--r--mediaapi/storage/storage_wasm.go6
5 files changed, 14 insertions, 14 deletions
diff --git a/mediaapi/storage/postgres/mediaapi.go b/mediaapi/storage/postgres/mediaapi.go
index 30ec64f8..5b668774 100644
--- a/mediaapi/storage/postgres/mediaapi.go
+++ b/mediaapi/storage/postgres/mediaapi.go
@@ -20,13 +20,12 @@ import (
_ "github.com/lib/pq"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/storage/shared"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
)
// NewDatabase opens a postgres database.
-func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions) (*shared.Database, error) {
- db, writer, err := base.DatabaseConnection(dbProperties, sqlutil.NewDummyWriter())
+func NewDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.Database, error) {
+ db, writer, err := conMan.Connection(dbProperties)
if err != nil {
return nil, err
}
diff --git a/mediaapi/storage/sqlite3/mediaapi.go b/mediaapi/storage/sqlite3/mediaapi.go
index c0ab10e9..4d484f32 100644
--- a/mediaapi/storage/sqlite3/mediaapi.go
+++ b/mediaapi/storage/sqlite3/mediaapi.go
@@ -19,13 +19,12 @@ import (
// Import the postgres database driver.
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/storage/shared"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
)
// NewDatabase opens a SQLIte database.
-func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions) (*shared.Database, error) {
- db, writer, err := base.DatabaseConnection(dbProperties, sqlutil.NewExclusiveWriter())
+func NewDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.Database, error) {
+ db, writer, err := conMan.Connection(dbProperties)
if err != nil {
return nil, err
}
diff --git a/mediaapi/storage/storage.go b/mediaapi/storage/storage.go
index f673ae7e..8e67af9f 100644
--- a/mediaapi/storage/storage.go
+++ b/mediaapi/storage/storage.go
@@ -20,19 +20,19 @@ package storage
import (
"fmt"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/storage/postgres"
"github.com/matrix-org/dendrite/mediaapi/storage/sqlite3"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
)
// NewMediaAPIDatasource opens a database connection.
-func NewMediaAPIDatasource(base *base.BaseDendrite, dbProperties *config.DatabaseOptions) (Database, error) {
+func NewMediaAPIDatasource(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (Database, error) {
switch {
case dbProperties.ConnectionString.IsSQLite():
- return sqlite3.NewDatabase(base, dbProperties)
+ return sqlite3.NewDatabase(conMan, dbProperties)
case dbProperties.ConnectionString.IsPostgres():
- return postgres.NewDatabase(base, dbProperties)
+ return postgres.NewDatabase(conMan, dbProperties)
default:
return nil, fmt.Errorf("unexpected database type")
}
diff --git a/mediaapi/storage/storage_test.go b/mediaapi/storage/storage_test.go
index 81f0a5d2..11febd27 100644
--- a/mediaapi/storage/storage_test.go
+++ b/mediaapi/storage/storage_test.go
@@ -5,6 +5,7 @@ import (
"reflect"
"testing"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/storage"
"github.com/matrix-org/dendrite/mediaapi/types"
"github.com/matrix-org/dendrite/setup/config"
@@ -13,7 +14,8 @@ import (
func mustCreateDatabase(t *testing.T, dbType test.DBType) (storage.Database, func()) {
connStr, close := test.PrepareDBConnectionString(t, dbType)
- db, err := storage.NewMediaAPIDatasource(nil, &config.DatabaseOptions{
+ cm := sqlutil.NewConnectionManager()
+ db, err := storage.NewMediaAPIDatasource(cm, &config.DatabaseOptions{
ConnectionString: config.DataSource(connStr),
})
if err != nil {
diff --git a/mediaapi/storage/storage_wasm.go b/mediaapi/storage/storage_wasm.go
index 41e4a28c..47ee3792 100644
--- a/mediaapi/storage/storage_wasm.go
+++ b/mediaapi/storage/storage_wasm.go
@@ -17,16 +17,16 @@ package storage
import (
"fmt"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/mediaapi/storage/sqlite3"
- "github.com/matrix-org/dendrite/setup/base"
"github.com/matrix-org/dendrite/setup/config"
)
// Open opens a postgres database.
-func NewMediaAPIDatasource(base *base.BaseDendrite, dbProperties *config.DatabaseOptions) (Database, error) {
+func NewMediaAPIDatasource(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (Database, error) {
switch {
case dbProperties.ConnectionString.IsSQLite():
- return sqlite3.NewDatabase(base, dbProperties)
+ return sqlite3.NewDatabase(conMan, dbProperties)
case dbProperties.ConnectionString.IsPostgres():
return nil, fmt.Errorf("can't use Postgres implementation")
default: