aboutsummaryrefslogtreecommitdiff
path: root/userapi/storage/accounts/postgres/storage.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-08-21 10:42:08 +0100
committerGitHub <noreply@github.com>2020-08-21 10:42:08 +0100
commit9d53351dc20283103bf2eec6b92831033d06c5a8 (patch)
tree653cf0ddca3f777bcdba188187fb78fe39ae2b02 /userapi/storage/accounts/postgres/storage.go
parent5aaf32bbed4d704d5a22ad7dff79f7a68002a213 (diff)
Component-wide TransactionWriters (#1290)
* Offset updates take place using TransactionWriter * Refactor TransactionWriter in current state server * Refactor TransactionWriter in federation sender * Refactor TransactionWriter in key server * Refactor TransactionWriter in media API * Refactor TransactionWriter in server key API * Refactor TransactionWriter in sync API * Refactor TransactionWriter in user API * Fix deadlocking Sync API tests * Un-deadlock device database * Fix appservice API * Rename TransactionWriters to Writers * Move writers up a layer in sync API * Document sqlutil.Writer interface * Add note to Writer documentation
Diffstat (limited to 'userapi/storage/accounts/postgres/storage.go')
-rw-r--r--userapi/storage/accounts/postgres/storage.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/userapi/storage/accounts/postgres/storage.go b/userapi/storage/accounts/postgres/storage.go
index 9653c019..b36264dd 100644
--- a/userapi/storage/accounts/postgres/storage.go
+++ b/userapi/storage/accounts/postgres/storage.go
@@ -34,7 +34,8 @@ import (
// Database represents an account database
type Database struct {
- db *sql.DB
+ db *sql.DB
+ writer sqlutil.Writer
sqlutil.PartitionOffsetStatements
accounts accountsStatements
profiles profilesStatements
@@ -49,27 +50,27 @@ func NewDatabase(dbProperties *config.DatabaseOptions, serverName gomatrixserver
if err != nil {
return nil, err
}
- partitions := sqlutil.PartitionOffsetStatements{}
- if err = partitions.Prepare(db, "account"); err != nil {
+ d := &Database{
+ serverName: serverName,
+ db: db,
+ writer: sqlutil.NewDummyWriter(),
+ }
+ if err = d.PartitionOffsetStatements.Prepare(db, d.writer, "account"); err != nil {
return nil, err
}
- a := accountsStatements{}
- if err = a.prepare(db, serverName); err != nil {
+ if err = d.accounts.prepare(db, serverName); err != nil {
return nil, err
}
- p := profilesStatements{}
- if err = p.prepare(db); err != nil {
+ if err = d.profiles.prepare(db); err != nil {
return nil, err
}
- ac := accountDataStatements{}
- if err = ac.prepare(db); err != nil {
+ if err = d.accountDatas.prepare(db); err != nil {
return nil, err
}
- t := threepidStatements{}
- if err = t.prepare(db); err != nil {
+ if err = d.threepids.prepare(db); err != nil {
return nil, err
}
- return &Database{db, partitions, a, p, ac, t, serverName}, nil
+ return d, nil
}
// GetAccountByPassword returns the account associated with the given localpart and password.